Has anyone had success with setting up virtualenv with mayapy?

577 views
Skip to first unread message

James Deschenes

unread,
Mar 7, 2018, 2:31:35 PM3/7/18
to Python Programming for Autodesk Maya

Has anyone had success with setting up virtual environments with mayapy? I'm seeing the following error and I'm guessing that the issue is with the python home and the binary being in different locations.

C:\dev\hg_checkouts\mayaenv>virtualenv --python="C:\Program Files\Autodesk\Maya2018\bin\mayapy.exe" test
Running virtualenv with interpreter C:\Program Files\Autodesk\Maya2018\bin\mayapy.exe
PYTHONHOME is set.  You *must* activate the virtualenv before using it
Traceback (most recent call last):
  File "c:\python27\lib\site-packages\virtualenv.py", line 2328, in <module>
    main()
  File "c:\python27\lib\site-packages\virtualenv.py", line 713, in main
    symlink=options.symlink)
  File "c:\python27\lib\site-packages\virtualenv.py", line 925, in create_environment
    site_packages=site_packages, clear=clear, symlink=symlink))
  File "c:\python27\lib\site-packages\virtualenv.py", line 1145, in install_python
    site_filename_dst = change_prefix(site_filename, home_dir)
  File "c:\python27\lib\site-packages\virtualenv.py", line 1036, in change_prefix
    (filename, prefixes)
AssertionError: Filename C:\Program Files\Autodesk\Maya2018\bin\python27.zip\site.py does not start with any of these prefixes: ['C:\\Program Files\\Autodesk\\Maya2018\\Python']


Robert White

unread,
Mar 7, 2018, 5:11:27 PM3/7/18
to Python Programming for Autodesk Maya
Maya does some things when it comes to how it deploys python that just aren't compatible with virtualenv.
The biggest hurdle is that they zip up the entire standard library, while virtualenv likes to copy and enhance certain files from the standard library so as to operate properly.

James Deschenes

unread,
Mar 8, 2018, 1:17:08 PM3/8/18
to Python Programming for Autodesk Maya
Yeah that's what I'm beginning to understand as well. I also need to manage the plug-in environment as well as some other things which will likely go beyond the scope of Python virtual environments. Thanks for confirming my suspicions.

Robert White

unread,
Mar 8, 2018, 3:09:22 PM3/8/18
to Python Programming for Autodesk Maya
The only time I've gotten virtualenv to operate was using a custom python build that matched the runtime environment of Maya (I was on windows, which meant compiling with a newer compiler), and then manually doing the dirty work to set all the paths and environment variables properly so that it could find all the maya packages and dlls.

In was a fun experiment, but felt like way more work than what I got out of it.

Andres Weber

unread,
Mar 8, 2018, 4:41:40 PM3/8/18
to Python Programming for Autodesk Maya
I usually make a venv out of a matching Python version and then just inject the path into Mayapy...not what you're looking for I know but it was the compromise I found was easiest.
Reply all
Reply to author
Forward
0 new messages