Python相当于node.js的npm链接,使用本地开发版本的要求?

dz6r00yl  于 12个月前  发布在  Node.js
关注(0)|答案(2)|浏览(126)

在Node.js中,我习惯于使用npm link来获得一个项目,以使用依赖项的自定义版本。从Node文档中:
首先,包文件夹中的npm link将创建一个从prefix/package-name到当前文件夹的全局安装符号链接。
接下来,在其他位置,npm link package-name将创建一个从本地node_modules文件夹到全局符号链接的符号链接。
通过符号链接到站点包中来做类似的事情是正确的吗?

ubby3x7f

ubby3x7f1#

精确的类似物是pip install -e .python setup.py develop
可编辑安装允许您安装项目而不复制任何文件。相反,开发目录中的文件会添加到Python的导入路径中。这种方法非常适合开发,也称为“开发安装”。
https://pip.pypa.io/en/latest/topics/local-project-installs/#editable-installs

pes8fvy9

pes8fvy92#

也许吧,但你可能想做的是使用virtualenv。Virtualenv允许你创建一个与任何其他环境隔离的Python环境:

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

字符串
然后,你可以根据自己的意愿安装特定版本的python包,比如我刚刚找到的一个随机的toolz包的0.1.0版本,而最新的版本是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...

相关问题