2013-05-21 76 views
2

我試圖設置virtualenv指向Maya 2013的可執行文件,所以我可以在shell中運行它的單元測試。 Maya使用位於/usr/autodesk/maya/bin/mayapy的自定義python 2.6可執行文件。我得到這些錯誤:virtualenv和Maya

$ virtualenv -p /usr/autodesk/maya/bin/mayapy mayapy 
Running virtualenv with interpreter /usr/autodesk/maya/bin/mayapy 
PYTHONHOME is set. You *must* activate the virtualenv before using it 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 2577, in <module> 
    main() 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 979, in main 
    no_pip=options.no_pip) 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1081, in create_environment 
    site_packages=site_packages, clear=clear)) 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1289, in install_python 
    writefile(site_filename_dst, SITE_PY) 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 445, in writefile 
    f = open(dest, 'wb') 
IOError: [Errno 2] No such file or directory: 'mayapy/lib/python26.zip/site.py' 

我讀過virtualenv's pagevirtualenv -h輸出,一些基本的virtualenv writeups像this one,並搜查谷歌和SO兩者的virtualenv和Maya +的virtualenv配對,都無濟於事。

下面是詳細的輸出:

$ virtualenv -vv -p /usr/autodesk/maya/bin/mayapy mayapy 
Running virtualenv with interpreter /usr/autodesk/maya/bin/mayapy 
PYTHONHOME is set. You *must* activate the virtualenv before using it 
Directory mayapy/lib/python2.6 already exists 
Symlinking Python bootstrap modules 
    Cannot import bootstrap module: os 
    Ignoring built-in bootstrap module: posix 
    Cannot import bootstrap module: posixpath 
    Cannot import bootstrap module: nt 
    Cannot import bootstrap module: ntpath 
    Cannot import bootstrap module: genericpath 
    Cannot import bootstrap module: fnmatch 
    Cannot import bootstrap module: locale 
    Cannot import bootstrap module: encodings 
    Cannot import bootstrap module: codecs 
    Cannot import bootstrap module: stat 
    Cannot import bootstrap module: UserDict 
    File mayapy/lib/python2.6/lib-dynload/readline.so already exists 
    Cannot import bootstrap module: copy_reg 
    Cannot import bootstrap module: types 
    Cannot import bootstrap module: re 
    Cannot import bootstrap module: sre 
    Cannot import bootstrap module: sre_parse 
    Cannot import bootstrap module: sre_constants 
    Cannot import bootstrap module: sre_compile 
    File mayapy/lib/python2.6/lib-dynload/zlib.so already exists 
    Cannot import bootstrap module: warnings 
    Cannot import bootstrap module: linecache 
    Cannot import bootstrap module: _abcoll 
    Cannot import bootstrap module: abc 
Directory mayapy/lib/python2.6/site-packages already exists 
Writing mayapy/lib/python26.zip/site.py 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 2577, in <module> 
    main() 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 979, in main 
    no_pip=options.no_pip) 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1081, in create_environment 
    site_packages=site_packages, clear=clear)) 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1289, in install_python 
    writefile(site_filename_dst, SITE_PY) 
    File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 445, in writefile 
    f = open(dest, 'wb') 
IOError: [Errno 2] No such file or directory: 'mayapy/lib/python26.zip/site.py' 
+0

我不知道答案,但看到評論一直很薄...我使用python創建virtualenvs我想虛擬化而不是使用-p選項:'/ usr/autodesk/maya/bin/mayapy virtualenv mayapy' – tdelaney

+0

我開始看到,雖然它花了一段時間才發現。這是否意味着我需要將virtualenv本身安裝到Maya的python中? –

+0

嘗試在'PYTHONPATH'環境變量中添加'/ usr/local/lib/python2.6/dist-packages'或'/ usr/autodesk/maya/bin/python26.zip'? –

回答

0

下載最新的virtualenv並與Python版本調用它的virtualenv要虛擬化:

/usr/autodesk/maya/bin/mayapy where/i/saved/virtualenv mayapy 
+0

'/ usr/autodesk/maya/bin/mayapy/usr/local/bin/virtualenv mayapy'給了我'ImportError:No module named pkg_resources'。 –

+0

@Gary Fixler - 這意味着你的python沒有[setuptools](https://pypi.python.org/pypi/setuptools)。您可以下載並安裝它(使用/ usr/autodesk/maya/bin/mayapy),並且至少可以更進一步。 – tdelaney

+0

看起來並不那麼容易。我在64位Linux上,所以它希望我下載並運行一個蛋殼文件,如shell腳本,它不會讓我選擇mayapy,或者我可以包含EasyInstall命令行選項,當然,我不會沒有注意到。我必須弄清楚下一步如何在64位Windows 7上再次執行此操作。 –

0

的替代方案,是很好的不搞亂單元測試你的Maya運行時環境是在maya.standalone的一個實例中運行你的測試。如果你的測試都包括這樣的事情:

import maya.standalone 
try: 
    maya.standalone.initialize() 
except: 
    pass # initialize raises if you call it more than once, but it's harmless if you catch it. 

可以從mayapy intepreter沒有GUI模式下運行Maya中運行它們。

+0

這就是我正在使用的。這是[一個正在進行的傳奇](http://stackoverflow.com/questions/12087780/is-there-any-way-to-install-nose-in-maya)。你可以看到我的一個評論[這裏](http://stackoverflow.com/questions/12087780/is-there-any-way-to-install-nose-in-maya/15213747#15213747),我想通了如何在Maya中進行easy_install,而且我確實有過鼻子的工作。不過,我收到了一個評論,讓我重新考慮了與Maya環境搞砸,所以我想看看virtualenv是否會讓我包裝mayapy,以便我可以暫時將我的全局環境切換到臨時運行測試。 –

+1

FWIW,我非常幸運,將所有maya代碼保存在一個zip文件中,並使用site.addsitedir(path/to/zip)將其添加到路徑中。我沒有以這種方式將任何東西安裝到maya目錄中,我可以通過更改userSetup.py中的一行或設置環境變量來交換工具集。這對測試來說也很好,因爲在測試時沒有舊的pyc文件帶有糟糕代碼的機會;) – theodox

+0

我想回來說謝謝。我最近有機會重新安裝Maya(系統崩潰),並且再次查看這個問題,看看我上次如何設置鼻子。我注意到拉鍊的想法,並給它一個旋轉。我沒有得到一個zip文件本身工作(嘗試.zip,.tar.gz,完整路徑,文件夾路徑等),但添加了一個'site.addsitedir('path/to/nose-1.3.0') '給我的userSetup.py找到未壓縮的目錄就好了。這是一個體面的設置。感謝您在今年早些時候推薦它。 –