8

In Node.js, I'm used to using npm link to get a project to use a custom version of a dependency. From the Node documentation:

First, npm link in a package folder will create a globally-installed symbolic link from prefix/package-name to the current folder.

Next, in some other location, npm link package-name will create a symlink from the local node_modules folder to the global symlink.

Is it kosher to do something similar by symlinking into site-packages?

Community
  • 1
  • 1
btown
  • 2,273
  • 3
  • 27
  • 38

2 Answers2

5

The exact analogue is pip install -e . or python setup.py develop.

https://pip.pypa.io/en/latest/reference/pip_install.html#editable-installs

Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
3

Perhaps, but what you probably want to do is use virtualenv. Virtualenv allows you to create a python environment isolated from any others:

$ virtualenv myenv
New python executable in myenv/bin/python
Installing setuptools............done.
Installing pip...............done.
$ source myenv/bin/activate

You can then install specific versions of python packages as you please, say version 0.1.0 of a random toolz package I just found, when the lastest version is 0.2.1:

(myenv)$ pip install toolz==0.1.0
Downloading/unpacking toolz==0.1.0
  Downloading toolz-0.1.tar.gz
  Running setup.py egg_info for package toolz
Downloading/unpacking itertoolz>=0.5 (from toolz==0.1.0)
  Downloading itertoolz-0.5.tar.gz
  Running setup.py egg_info for package itertoolz
Downloading/unpacking functoolz>=0.4 (from toolz==0.1.0)
  Downloading functoolz-0.4.tar.gz
  Running setup.py egg_info for package functoolz
Installing collected packages: toolz, itertoolz, functoolz
  Running setup.py install for toolz
  Running setup.py install for itertoolz
  Running setup.py install for functoolz
Successfully installed toolz itertoolz functoolz
Cleaning up...

As you can see it also installs dependencies. You can also generate a requirements file:

(myenv)$ pip freeze
functoolz==0.4
itertoolz==0.5
toolz==0.1
wsgiref==0.1.2

Which you can then use to duplicate those same dependencies in another virtualenv

(myenv)$ pip freeze > reqs.txt
(myenv)$ deactivate
$ source env2/bin/activate
(env2)$ pip freeze
wsgiref==0.1.2
(env2)$ pip install -r reqs.txt 
Downloading/unpacking functoolz==0.4 (from -r reqs.txt (line 1))
  Downloading functoolz-0.4.tar.gz
  Running setup.py egg_info for package functoolz
Downloading/unpacking itertoolz==0.5 (from -r reqs.txt (line 2))
  Downloading itertoolz-0.5.tar.gz
  Running setup.py egg_info for package itertoolz
Downloading/unpacking toolz==0.1 (from -r reqs.txt (line 3))
  Downloading toolz-0.1.tar.gz
  Running setup.py egg_info for package toolz
Requirement already satisfied (use --upgrade to upgrade): wsgiref==0.1.2 in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6 (from -r reqs.txt (line 4))
Installing collected packages: functoolz, itertoolz, toolz
  Running setup.py install for functoolz
  Running setup.py install for itertoolz
  Running setup.py install for toolz
Successfully installed functoolz itertoolz toolz
Cleaning up...
Claudiu
  • 224,032
  • 165
  • 485
  • 680
  • 2
    This does not correctly answer the author question about installing local versions of a package. virtualenv allows you to install different version but it doesn't solve the issue of how to link between a local package version to the project you want to install it on. – Chaos Monkey Jan 05 '20 at 12:56