我想创建一个不使用符号链接到本地系统的virtualenv,因为我希望将virtualenv(包括第三方包)与我的应用程序捆绑在一起。这可能 - 如果是的话,怎么样?
例如,在我的Mac OS X 10.10.2上,我创建的任何virtualenv都包含符号链接:
.Python -> /System/Library/Frameworks/Python.framework/Versions/2.7/Python
如果我直接在--always-copy
的网络服务器共享上创建virtualenv,则会收到错误消息:
$ virtualenv --always-copy python2.7.9_win7-64_stalker0.2.13
New python executable in python2.7.9_win7-64_stalker0.2.13/bin/python
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 11, in <module>
sys.exit(main())
File "/Library/Python/2.7/site-packages/virtualenv.py", line 825, in main
symlink=options.symlink)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 985, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/Library/Python/2.7/site-packages/virtualenv.py", line 1374, in install_python
symlink)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 482, in copyfile
copyfileordir(src, dest, symlink)
File "/Library/Python/2.7/site-packages/virtualenv.py", line 456, in copyfileordir
shutil.copy2(src, dest)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2
copystat(src, dst)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat
os.chflags(dst, st.st_flags)
OSError: [Errno 22] Invalid argument: 'python2.7.9_win7-64_stalker0.2.13/.Python'
答案 0 :(得分:1)
也许可以尝试解决更大的问题(合理的包装)而不是调整virtualenv内部?
例如,看一下http://platter.pocoo.org/或者http://cx-freeze.sourceforge.net/可能(我不确定你的意思是哪种情况)。
答案 1 :(得分:0)
使用Python 3和venv
模块,可以使用--copies
flag创建一个没有符号链接的“厚”虚拟环境:
$ python -m venv --copies thick_venv
$ ls -l thick_venv/bin/
total 36836
-rw-r--r--. 1 br0ke br0ke 2230 May 19 17:54 activate
-rw-r--r--. 1 br0ke br0ke 1282 May 19 17:54 activate.csh
-rw-r--r--. 1 br0ke br0ke 2434 May 19 17:54 activate.fish
-rw-r--r--. 1 br0ke br0ke 8832 May 19 17:54 Activate.ps1
-rwxr-xr-x. 1 br0ke br0ke 266 May 19 17:54 easy_install*
-rwxr-xr-x. 1 br0ke br0ke 266 May 19 17:54 easy_install-3.8*
-rwxr-xr-x. 1 br0ke br0ke 248 May 19 17:54 pip*
-rwxr-xr-x. 1 br0ke br0ke 248 May 19 17:54 pip3*
-rwxr-xr-x. 1 br0ke br0ke 248 May 19 17:54 pip3.8*
-rwxr-xr-x. 1 br0ke br0ke 18833904 May 19 17:54 python*
-rwxr-xr-x. 1 br0ke br0ke 18833904 May 19 17:54 python3*
如您所见,它将解释器复制到虚拟环境中(两次)。这是带有符号链接的常见虚拟环境的示例:
$ python -m venv thin_venv
$ ls -l thin_venv/bin/
total 44
-rw-r--r--. 1 br0ke br0ke 2227 May 19 17:54 activate
-rw-r--r--. 1 br0ke br0ke 1279 May 19 17:54 activate.csh
-rw-r--r--. 1 br0ke br0ke 2431 May 19 17:54 activate.fish
-rw-r--r--. 1 br0ke br0ke 8832 May 19 17:54 Activate.ps1
-rwxr-xr-x. 1 br0ke br0ke 265 May 19 17:54 easy_install*
-rwxr-xr-x. 1 br0ke br0ke 265 May 19 17:54 easy_install-3.8*
-rwxr-xr-x. 1 br0ke br0ke 247 May 19 17:54 pip*
-rwxr-xr-x. 1 br0ke br0ke 247 May 19 17:54 pip3*
-rwxr-xr-x. 1 br0ke br0ke 247 May 19 17:54 pip3.8*
lrwxrwxrwx. 1 br0ke br0ke 50 May 19 17:54 python -> /home/br0ke/.asdf/installs/python/3.8.3/bin/python*
lrwxrwxrwx. 1 br0ke br0ke 6 May 19 17:54 python3 -> python*