2

我正在尝试将 virtualenv 设置为指向 Maya 2013 的可执行文件,以便我可以在 shell 中运行单元测试。Maya 使用位于/usr/autodesk/maya/bin/mayapy. 我收到这些错误:

$ 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 的页面、输出、一些像这样virtualenv -h的基本 virtualenv 文章,并在 google 和 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'
4

2 回答 2

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 解释器运行它们,而无需在 gui 模式下运行 maya。

于 2013-05-24T02:32:30.393 回答
0

下载最新的 virtualenv 并使用您要虚拟化的 python 版本将其命名为 virtualenv:

/usr/autodesk/maya/bin/mayapy where/i/saved/virtualenv mayapy
于 2013-05-22T02:43:54.190 回答