2

I recently developed a package my_package and am hosting it on GitHub. For easy installation and use, I have following setup.py:

from setuptools import setup

setup(name='my_package',
      version='1.0',
      description='My super cool package',
      url='https://github.com/my_name/my_package',
      packages=['my_package'],
      python_requieres='3.9',
      install_requires=[
            'some_package==1.0.0'
      ])

Now I am trying to install this package in a conda environment:

conda create --name myenv python=3.9
conda activate myenv 
pip install git+'https://github.com/my_name/my_package'

So far so good. If I try to use it in the project folder, everything works perfectly. If I try to use the packet outside the project folder (still inside the conda environment), I get the following error: ModuleNotFoundError: No module named 'my_package'

I am working on windows, if that matters.

EDIT:

I'm verifying that both python and pip are pointing towards the correct version with:

which pip 
which python

/c/Anaconda3/envs/my_env/python
/c/Anaconda3/envs/my_env/Scripts/pip

Also, when I run:

pip show my_package

I get a description of my package. So pip finds it, but as soon as I try to import my_package in the script, I get the described error.

I also verified that the package is installed in my environment. So in /c/Anaconda3/envs/my_env/lib/site-packages there is a folder my_package-1.0.dist-info/

Further: python "import sys, print(sys.path)"

shows, among other paths, /c/Anaconda3/envs/my_env/lib/site-packages. So it is in the path.

Zeitproblem
  • 165
  • 1
  • 12
  • 1
    Related: https://stackoverflow.com/questions/50995662/how-to-have-egg-files-from-github-install-with-pip-not-in-current-directory-but – merv Jun 29 '22 at 17:08
  • Dit not help solving the issue – Zeitproblem Jul 28 '22 at 10:56
  • Okay. Could you please add some more details about the situation? Where is the package getting installed if not in the environment's `${CONDA_PREFIX}/lib/python3.9/site-packages`? How are you verifying that the environment is properly activated and that the `pip` corresponds to the environment? – merv Jul 28 '22 at 19:16
  • To create and activate the environment I run the commands described in my post. If I then run ´conda list´ with this environment activated, I can see my_package listed. Also both ´which python´ and ´which pip´ correspond to the environment environmentfolder. – Zeitproblem Jul 29 '22 at 07:58
  • I updated my original post with some additional information – Zeitproblem Jul 29 '22 at 08:26

3 Answers3

1

Check if you are using some explicit shebang in your script pointing to other Python interpreters.

Eg. using the system default Python:

#!/bin/env python
...
albeus
  • 156
  • 1
  • 2
1

While inside your environment myenv, try to uninstall your package first, to do a clean test:

pip uninstall my_package

Also, you have a typo in your setup.py: python_requieres --> python_requires.

And I actually tried to install with your setup.py, and also got ModuleNotFoundError - but because it didn't properly install due to install_requires:

ERROR: Could not find a version that satisfies the requirement some_package==1.0.0

So, check also that everything installs without errors and warnings.

Hope that helps.

qaziqarta
  • 1,782
  • 1
  • 4
  • 11
0

First thing I would like to point out (not the solution) regards the following statement you made:

If I try to use it in the project folder [...] If I try to use the packet outside the project folder [...]

I understand "project folder" means the "my_package" folder (inside the git repository). If that is the case, I would like to point out that you are mixing two situations: that of testing a (remote) package installation, while in your (local) repository. Which is not necessarily wrong, but error-prone.

Whenever testing the setup/install process of a package, make sure to move far from your repository (say, "/tmp/" equivalent in Windows) and, preferably, use a fresh environment. That will eliminate "noise" in your tests.

  1. First thing I would tell you to do -- if not already -- is to create a fresh conda env and install your package from an empty/new folder. Eg,

    $ conda env create -n test_my_package ipython pip
    $ cd /tmp    # equivalent temporary or new in your Windows
    $ pip install git+https://github.com/my_name/my_package
    
  2. If that doesn't work (maybe a problem with your pip' git+http code), do another way: create a release for your package (eg, "v1") and then install the released version by indicating the zip package URL (that you get from your "my_package" releases page on Github):

    $ pip install https://github.com/my_name/my_package/archive/v1.zip
    
Brandt
  • 5,058
  • 3
  • 28
  • 46