在 Node.js 中,我习惯于npm link
让项目使用自定义版本的依赖项。从节点文档:
首先,
npm link
在一个包文件夹中将创建一个从全局安装prefix/package-name
到当前文件夹的符号链接。接下来,在其他位置,
npm link package-name
将创建从本地node_modules
文件夹到全局符号链接的符号链接。
通过符号链接到站点包中做类似的事情是否符合规定?
确切的类比是pip install -e .
or python setup.py develop
。
https://pip.pypa.io/en/latest/reference/pip_install.html#editable-installs
也许,但您可能想要做的是使用virtualenv。Virtualenv 允许你创建一个与其他环境隔离的 python 环境:
$ virtualenv myenv
New python executable in myenv/bin/python
Installing setuptools............done.
Installing pip...............done.
$ source myenv/bin/activate
然后,您可以随意安装特定版本的 python 包,比如我刚刚找到0.1.0
的随机包的版本,最新版本是:toolz
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...
如您所见,它还安装了依赖项。您还可以生成需求文件:
(myenv)$ pip freeze
functoolz==0.4
itertoolz==0.5
toolz==0.1
wsgiref==0.1.2
然后您可以使用它在另一个 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...