2014-04-24 89 views
5

也許我並不清楚virtualenv是如何工作的,但是如果我用--always-copy標誌運行virtualenv,我期望所有文件內部/ lib/python被複制。virtualenv不會複製lib/python目錄中的所有.py文件

所以我創建了一個虛擬的ENV

virtualenv -v --always-copy myenv 

輸出的是

Creating myenv/lib/python2.7 
Symlinking Python bootstrap modules 
    Copying to myenv/lib/python2.7/config 
    Copying to myenv/lib/python2.7/lib-dynload 
    Copying to myenv/lib/python2.7/os.py 
    Ignoring built-in bootstrap module: posix 
    Copying to myenv/lib/python2.7/posixpath.py 
    Cannot import bootstrap module: nt 
    Copying to myenv/lib/python2.7/ntpath.py 
    Copying to myenv/lib/python2.7/genericpath.py 
    Copying to myenv/lib/python2.7/fnmatch.py 
    Copying to myenv/lib/python2.7/locale.py 
    Copying to myenv/lib/python2.7/encodings 
    Copying to myenv/lib/python2.7/codecs.py 
    Copying to myenv/lib/python2.7/stat.py 
    Copying to myenv/lib/python2.7/UserDict.py 
    File myenv/lib/python2.7/lib-dynload/readline.so already exists 
    Copying to myenv/lib/python2.7/copy_reg.py 
    Copying to myenv/lib/python2.7/types.py 
    Copying to myenv/lib/python2.7/re.py 
    Copying to myenv/lib/python2.7/sre.py 
    Copying to myenv/lib/python2.7/sre_parse.py 
    Copying to myenv/lib/python2.7/sre_constants.py 
    Copying to myenv/lib/python2.7/sre_compile.py 
    File myenv/lib/python2.7/lib-dynload/zlib.so already exists 
    Copying to myenv/lib/python2.7/warnings.py 
    Copying to myenv/lib/python2.7/linecache.py 
    Copying to myenv/lib/python2.7/_abcoll.py 
    Copying to myenv/lib/python2.7/abc.py 
    Copying to myenv/lib/python2.7/_weakrefset.py 
Creating myenv/lib/python2.7/site-packages 
Writing myenv/lib/python2.7/site.py 
Writing myenv/lib/python2.7/orig-prefix.txt 
Writing myenv/lib/python2.7/no-global-site-packages.txt 
Creating parent directories for myenv/include 
Copying to myenv/include/python2.7 
Creating myenv/bin 
New python executable in myenv/bin/python 
Changed mode of myenv/bin/python to 0755 
Copying to myenv/bin/python2 
Copying to myenv/bin/python2.7 
Testing executable with myenv/bin/python -c "import sys;out=sys.stdout;getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))" 
Got sys.prefix result: u'/home/rbouza/myenv' 
Creating myenv/lib/python2.7/distutils 
Writing myenv/lib/python2.7/distutils/__init__.py 
Writing myenv/lib/python2.7/distutils/distutils.cfg 
Installing setuptools, pip... 
    Running command /home/rbouza/myenv/bin/python -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip 
    Ignoring indexes: https://pypi.python.org/simple/ 
    Downloading/unpacking setuptools 
    Downloading/unpacking pip 
    Installing collected packages: setuptools, pip 
    Successfully installed setuptools pip 
    Cleaning up... 
...Installing setuptools, pip...done. 
Writing myenv/bin/activate 
Writing myenv/bin/activate.fish 
Writing myenv/bin/activate_this.py 
Writing myenv/bin/activate.csh 

然後我去到lib目錄

cd myenv/lib/python2.7 

列表中的所有文件

_abcoll.py config  fnmatch.pyc  locale.py     os.pyc  
    site.py   sre_parse.py types.pyc  _weakrefset.pyc 
_abcoll.pyc copy_reg.py genericpath.py locale.pyc     posixpath.py site.pyc   sre_parse.pyc UserDict.py 
abc.py  copy_reg.pyc genericpath.pyc no-global-site-packages.txt posixpath.pyc sre_compile.py  sre.py   UserDict.pyc 
abc.pyc  distutils  lib-dynload  ntpath.py     re.py   sre_compile.pyc stat.py  warnings.py 
codecs.py encodings  linecache.py  orig-prefix.txt    re.pyc   sre_constants.py stat.pyc  warnings.pyc 
codecs.pyc fnmatch.py linecache.pyc os.py      site-packages sre_constants.pyc types.py  _weakrefset.py 

這正是:50,包括目錄,但後來當我數在Python安裝目錄,我得到200 +的文件/文件顯示目錄(只有1級,不計站點包等)

有誰知道這是爲什麼這是行爲嗎?

甚至沒有__future__.py在那裏。

謝謝。

+0

我只是碰到了這個自己,我沒有想到virtualenv這樣的詭計! –

+0

我有和python3.4.3的virtualenv相同的問題:( – roboslone

回答

2

你不會指望virtualenv爲你的python庫做不必要的完全重複。

您的虛擬Python仍然引用並讀取您的根Python環境中的庫文件。虛擬環境的功能是在虛擬環境中設置新的庫安裝路徑,這樣進一步的庫安裝將被限制在這個虛擬環境中。

--always-copy 

此選項僅使virtualenv複製必要的文件而不是符號鏈接。

0

這是從手動

--always拷貝 始終複製文件,而不是符號鏈接。

的一點是,通常沒有這個選項的virtualenv應該只是符號鏈接所需的最低文件以節省空間。然後該選項確保這些文件的副本。

它沒有說任何關於複製其餘文件(特別是你安裝的額外網站軟件包)。

您需要使用--always-copy看起來像是您的新/額外項目軟件包的一部分,您可能還想使用Python的系統站點軟件包。

有這個選項爲:

如果您構建具有的virtualenv --system-site-packages中ENV,你的虛擬環境 將從 /usr/lib/python2.7/site繼承包(或全球 site-packages目錄)。

+0

我發現使用--system-site-packages不會複製lib目錄中提到的__future_.py。 – Matyas

相關問題