Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip install local package to target directory

I have a Python library that is published to PyPI. Before pushing each new version of the library, I want to test it by upgrading a sample application to use the new version.

The suggested method to do this is to work in "development mode" using the -e (--editable) flag:

$ pip install -e <my package root>

And this does indeed install the package into my global environment.

However, my sample program is written for Google App Engine, which requires that all third-party libraries be copied into an application-specific folder (./lib in my case). I normally install packages here by using the -t (--target) option to pip:

$ pip install -t lib/ <package>

However, it appears that the -e and -t options are not compatible, and my attempts to install my local, unpublished library to a specified target folder by using both flags together fail.

How can I test my library package by installing it in a custom directory before publishing?

like image 726
Myk Willis Avatar asked Nov 29 '17 05:11

Myk Willis


People also ask

Can you pip install local package?

Install the downloaded package into a local directory : python get-pip.py --user This will install pip to your local directory (. local/bin) . Now you may navigate to this directory (cd . local/bin) and then use pip or better set your $PATH variable this directory to use pip anywhere : PATH=$PATH:~/.

How do I choose where pip installs?

Click on the Advanced system settings link on the left panel. Click Environment Variables. Under System Variables, double-click the variable PATH. Click New, and add the directory where pip is installed, e.g. C:Python33Scripts, and select OK.

How do I install a local package in Python?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.


1 Answers

For one-time testing of a new package, installing directly from the local filesystem seems to be the best bet:

$ cd /my/sample/application
$ pip install -t lib /my/local/package

This install won't stay in sync as I make further changes to the local package (as it would if I were to use pip install --editable), but I can live without that for this use case.

I couldn't get @pbaranay's answer to work because of the way pip install -e uses "egg-info" files that apparently are not understood/traversed by GAE's dev_appserver.py script. The suggestion to create a virtualenv and symlink it to lib (rather than installing packages directly to lib with -t) is a good one, though.

like image 183
Myk Willis Avatar answered Oct 05 '22 00:10

Myk Willis