Pip: Editable requirements don't get symlinked properly.

Created on 19 Jan 2012  路  8Comments  路  Source: pypa/pip

I'm running pip 1.0.2 on Ubuntu in a virtual environment. When using an editable requirement in a requirements file:
-e git+file:///path/to/repo@branch#egg=egg_name
the installation with 'pip install -r requirements' works mostly as expected, checking out the code to 'VENV/src/egg-name'.

The package doesn't show up in the python path though. There is a text file in site-packages 'egg-name.egg-link' which contains the path 'VENV/src/egg-name'. If I make a symlink to 'VENV/src/egg-name' in site-packages manually, all is well.

There is a stack overflow question addressing this issue as well:
http://stackoverflow.com/questions/7926060/python-package-install-using-pip-to-source-doesnt-create-a-symlink

auto-locked

Most helpful comment

Pip uses a feature of setuptools to handle the installation of those editable requirements, known for the -e (or --editable) in front of it. Behind the scenes pip will actually simply call python setup.py develop (more or less) which creates the *.egg-link file. On Python level it acts like a symlink which means no additional symlink is needed on the file system.

Try opening the virtualenv's Python command (VENV/bin/python) and import the module you wanted to install editable. What does youmodule.__file__ give you?

Here is a little more background about how this works: http://api.rst2a.com/1.0/rst2/html?uri=http://svn.python.org/projects/sandbox/trunk/setuptools/doc/formats.txt#egg-links

All 8 comments

Pip uses a feature of setuptools to handle the installation of those editable requirements, known for the -e (or --editable) in front of it. Behind the scenes pip will actually simply call python setup.py develop (more or less) which creates the *.egg-link file. On Python level it acts like a symlink which means no additional symlink is needed on the file system.

Try opening the virtualenv's Python command (VENV/bin/python) and import the module you wanted to install editable. What does youmodule.__file__ give you?

Here is a little more background about how this works: http://api.rst2a.com/1.0/rst2/html?uri=http://svn.python.org/projects/sandbox/trunk/setuptools/doc/formats.txt#egg-links

Thanks so much for this detailed answer on how it's supposed to work. Really appreciated!

Gladly, I hope this works for you now.

FWIW, a bit more detail: the .egg-link file is actually just a marker file; what causes the package to be importable is the entry that is added to easy-install.pth. pth files are a built-in feature of Python; see http://docs.python.org/library/site.html

I have an interesting situation:

  • pip install -e git_...repo#egg=repo
  • egg-link file is created in site-packages,
  • correct entry added to easy-install.pth file,
  • repo cloned to VENV/src

but still unable to import module.

Symlinking or copying the repo to site-packages fixes this.
Any idea what's going on?

Update: Solved -
The issue was the structure of the project.
If I'm not mistaken, the common (correct) way to structure python projects:
my_project
|-- README
|-- my_package
|-- |-- __init__.py
|-- |-- my_subpackage

And in this case if you pip install -e git_...my_project#egg=my_package
Then you will be able to import my_package.
My project had the python package directory at the top level and therefore import my_package did not work, but (I later discovered) import my_subpackage did.

@liorsbg Your folder structure stuff just relieved me from several hours of dealing with this issue myself. Thx!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings