ImportError: Package installed from Git using pip not found by Python

Viewed 3184

I'm trying to use pip to install a package from a remote Git repo. The install seems to work fine:

$ pip install git+https://github.com/<me>/<mypackage>.git
...
Installing collected packages: <mypackage>
    Running setup.py install for <mypackage> ... done
Successfully installed <mypackage>-1.0.0.dev1
$ pip freeze | grep <mypackage>
<mypackage>==1.0.0.dev1
ls ls /usr/local/lib/python2.7/site-packages | grep <mypackage>
<mypackage>-1.0.0.dev1-py2.7.egg-info

But the package import fails:

$ python
>>> import <mypackage>
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
ImportError: No module named <mypackage>
>>>

I've been able to successfully install and import it from a local version:

$ pip install -e <path-to-mypackage>

but I'd like to be able to install it through git.

Under what conditions can a package (apparently) successfully pip install, but not be imported by Python?

The structure of my module is:

<mypackage>
    setup.py
    <mypackage>
        __init__.py
        # some files

I'm running OS X 10.11.6 and a brew-installed version of Python 2.7.13 and pip.

1 Answers

The repository cloned by you is not a python package.It is rather a folder containing the package.

To import the package simply cd into the inner my <mypackage> folder and then try to import it. But it's not a good idea, rather you may run the setup.py file contained in the outer <mypackage>folder to set up everything for you.This will also (usually) add the package to the environment variable so that you can import it from anywhere.

Related