9

ISSUE: I would like to install local package in a specific conda environment. To do that, I read the current documentation (python-packaging).

package structure:

$ pwd
~/…/test
.
|- requirements.txt
|- my_package
|   |-- __init__.py
|   |-- base.py
|- setup.py

setup.py

# -*- coding: utf-8 -*-

import os
from setuptools import setup

with open('requirements.txt') as f:
    requirements = f.read().splitlines()

setup(
    name='my_package',
    version='2.0.0',
    author='B.Gees',
    author_email='B.Gees@gmail.com',
    license='MIT',
    packages=['my_package'],
    description='my package description',
    long_description='my package long description',
    keywords='chemistry machine learning cheminformatics',
    classifiers=[
        'Environment :: Console',
        'Intended Audience :: Developers',
        'Intended Audience :: Healthcare Industry',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.5.5',
        'Topic :: Scientific/Engineering',
        'Topic :: Scientific/Engineering :: Bio-Informatics',
        'Topic :: Scientific/Engineering :: Chemistry',
        'Topic :: Scientific/Engineering :: Pharmacokinetic',
        'Topic :: Software Development :: Libraries :: Python Modules',
    ],
    install_requires=requirements,
    zip_safe=False
)

requirements.txt

pandas==0.19.2
dill==0.2.7.1
cython==0.23.4

__init__.py

# -*- coding: UTF-8 -*-

"""
my_package
~~~~~~~~~~

my package full description

:copyright: (c) 2018 by B.Gees.
:license: MIT, see LICENSE file for more details.
"""

from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
import logging

__title__ = 'my_package'
__version__ = '2.0.0'
__author__ = 'B.Gees'
__email__ = 'B.Gees@gmail.com'
__license__ = 'MIT'
__copyright__ = 'Copyright 2018 B.Gees'

log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())

base.py

# -*- coding: UTF-8 -*-

def titi(x):
    return x**2

I install my package in a specific conda environment with the folowing code lines:

conda activate my_env
pip install . # In my package repository

Nevertheless, when I try to import my_package in jupyter notebook, I obtain the following error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-9-daa52839320b> in <module>()
----> 1 import my_package

ImportError: No module named 'my_package'

This installation works fine when I used python pip outer conda environment.

QUESTION: I don't know how to install my package correctly in a specific conda environment. I need your lights to enlighten me.

CONFIGURATION: MacOSX with conda3 and python3.5 ; Need to be compatible with Linux 7

B.Gees
  • 1,125
  • 2
  • 11
  • 28
  • did you tried to use conda install my_package ? you can also use conda search my_package in your env to check if the package is well installed – C.med Oct 30 '18 at 09:58
  • Doesn't work for me :/ – B.Gees Oct 30 '18 at 09:59
  • what is the output of conda search my_package – C.med Oct 30 '18 at 10:00
  • `PackagesNotFoundError: The following packages are not available from current channels:Current channels: - https://repo.anaconda.com/pkgs/main/osx-64` It dosn't take into account my local environment – B.Gees Oct 30 '18 at 10:01
  • So the package is not installed in your env, try to use pip install my_package, until using pip install . – C.med Oct 30 '18 at 10:03
  • `pip install my_package` and `pip install .` give the same output : `Successfully installed my_package`. In jupyter notebook I have the same `ImportError` – B.Gees Oct 30 '18 at 10:08
  • You can also link the folder in the development mode with anaconda `conda develop ` - https://docs.conda.io/projects/conda-build/en/latest/resources/commands/conda-develop.html – Felipe Ferrari ferrari212 Apr 05 '22 at 12:36

1 Answers1

1

You are using MacOSX, so you should firstly use source activate yourenvname, then you can use what you did to install your package. for more information How to activate an Anaconda environment

so start with : conda create --name my_env python=3.5 then source activate my_env

C.med
  • 581
  • 1
  • 5
  • 21
  • I already activate my environment before install local package. This doesn't fix my issue :/. – B.Gees Oct 30 '18 at 10:18
  • did you tried to just import your package in the terminal; run python and then import my_package?without using jupiter – C.med Oct 30 '18 at 10:29
  • Yes, but this is the same problem – B.Gees Oct 30 '18 at 10:30
  • try to use : `/anaconda/envs/my_env/bin/pip install my_package` works only if you have `my_env` in `/anaconda/envs/`. I suggest you to use also `conda install pip` before doing that – C.med Oct 30 '18 at 10:36
  • 1
    I have tried these solutions. I realize that the explanation of my problem is not clear and I apologize for that. I'm preparing an update to explain you all the things I've tested. – B.Gees Oct 30 '18 at 10:51
  • @B.Gees if you succeed to install your package in your local machine, the problem is then due to your configuration of anaconda. waiting for your edit :) – C.med Oct 30 '18 at 11:01
  • 1
    when I recreate a new environment, I no longer have a problem. I have only updated my pip `You are using pip version 10.0.1, however version 18.1 is available` and it works. It's surprising. I can still offer you my update to see if the process is correct? – B.Gees Oct 30 '18 at 11:21
  • 1
    I used the folowing command lines: `conda create --name my_package python=3.5 --no-default-packages` ; ` source activate my_package` ; `conda install jupyter` ; `conda install pip` ; `pip install --upgrade pip` ; `pip install .` and my_package is available in my conda environement. Thanks a lot C.med for your attention – B.Gees Oct 30 '18 at 11:29