PYTHONPATH and maya.env


#1

Hey,

We’ve started taking a look, but run into issues with Pyblish setting the PYTHONPATH environment var.
We’re currently using Maya.env to set version specific vars for our tools.
Any paths set to PYTHONPATH in the Maya.env appear to be ignored (including after appending %PYTHONPATH% to either).

Any ideas?

Thanks,
Lee


#2

Hi Lee,

Do you mean Pyblish is setting/altering the PYTHONPATH for you? Or that you when you add Pyblish to your PYTHONPATH, it isn’t getting picked up?

To add Pyblish, we first need to figure out which install you are running. If you are using the recommended distribution for your platform, which seem to be Windows (looking att he % symbols) and should be Pyblish for Windows then you should find a /pythonpath subdirectory within that install which is what you are meant to add to your PYTHONPATH.

Try this, from a console on Windows.

$ set PYTHONPATH=c:\path\to\pyblish-win\pythonpath
$ set PYTHONPATH=c:\path\to\pyblish-win\lib\pyblish-x\integrations\maya;%PYTHONPATH%
$ c:\program files\autodesk\maya2016\bin\maya.exe

This will replace anything you currently have on your PYTHONPATH temporarily, and launch Maya with its Pyblish integration.

Within Maya, try importing Pyblish.

import pyblish

If that works, have a look in your file-menu for a new “Publish” option.

Let me know how it goes!


#3

Thanks Marcus and apologies, I shouldn’t be writing posts when I’m half asleep.

I am running the windows installer, Pyblish is editing my PYTHONPATH and is indeed working.
My problem is that now my Maya.env doesn’t affect PYTHONPATH and our tools no longer work.
The paths set in Maya.env only appear to work once I’ve completely removed the PYTHONPATH environment variable from windows.

I could add Pyblish to the Maya.env, however I’d rather find away for both to work to reduce any potential changes to our current structure.

I was wondering if anyone has encountered clashes like this before?

Thanks again,
Lee


#4

Aha, that is interesting.

The installer will modify your local PYTHONPATH for your currently logged on user, Maya.env must not be liking that very much and I haven’t heard of anyone else having this problem.

But it is perfectly safe to remove Pyblish from that path, and add it however you like.

If Pyblish is the only variable in that PYTHONPATH, then it sounds like Maya would be the happiest by you removing it altogether.

The upper portion of this GUI is your local variables.

Studio Install

However, since it sounds like you are running Pyblish within a studio, then there is an alternative method of installation that is recommended, which is this right here.

The difference here is that environment variables are left for you to handle, and that you can install it to a custom location, such as on a shared server. The installer is primarily for first-contact and getting familiar with Pyblish at home.


#5

@ldunham1, could you post your Maya.env?

Are you append to the PYTHONPATH? Heres a .mod file from arnold, which I’m guessing is using the same syntax as the .env file, where it appends to the PATH environment variable:

+ mtoa any ..\2015
PATH +:= bin

BTW good to see you here @ldunham1:)


#6

Lovely, thanks Marcus. Will give it a go next chance I get.


#7

@tokejepsen

the syntax is different but behaviour should be the same.
It’s essentially;

PYTHONPATH=Z:\tools\anim\python\2.7\

To which I’d expect it to already append existing vars. I did also test;

PYTHONPATH=%PYTHONPATH%;Z:\tools\anim\python\2.7\

to no avail.

Hahaha, I have taken my time! Some really nice work here guys :smile:


#8

Sorry, but did you say that when you remove Pyblish from your PYTHONPATH, the Maya.env would start working normally again? Or was it after the installation that suddenly it stopped working, regardless of what you do?


#9

Had a brief go with Maya.env, and it kinda worked here. The inclusion of %PYTHONPATH%, doesn’t seem to resolve, so you end up with something like:

%PYTHONPATH%;C:\Users\toke.jepsen\Documents\pyblish\pyblish

Pyblish still works when all the paths are in PYTHONPATH. Maybe try += instead:

PYTHONPATH += C:\Users\toke.jepsen\Documents\pyblish\pyblish

#10

Continuing the discussion from PYTHONPATH and maya.env:

Removing PYTHONPATH from the user environment variables and maya.env worked.

Tried Maya 2016 and Maya 2013


#11

Thanks @tokejepsen, I’ll give it a go.
I know its an issue with Maya.env, NOT Pyblish - apologies I should’ve made that clear.
The topic was to find out if anyone here has experienced this issue and if so how to resolve.

Thanks


#12

No worries, @ldunham1, we’re happy to help regardless. =) Sorry though, I haven’t used Maya.env enough to know for sure what’s going on. Maybe @tokejepsen has some more ideas.


#13

Just here to confirm that indeed setting PYTHONPATH as an environment variable will override Maya.env loading it correctly. I’m not sure why, but it’s really inconvenient.

It’s the same if the PYTHONPATH being set is just “appending” to whatever exists. I’m not sure what happens when you actually set the environment variable to %PYTHONPATH%;pyblish/path. Though using set or setx would actually store the %PYTHONPATH% as an expanded variable so that wouldn’t set it like that either.


#14

Wow, that is unexpected. Thanks for looking into it @BigRoy, definitely something to watch out for.


#15

Here is a thread on the Python Inside Maya group about this issue.

Though he’s only investigating Fedora, it would seem that it affects Windows also.


#16
import sys
if "C:\\My_Python_Lib" not in sys.path:
    sys.path.append("C:\\My_Python_Lib")

More on…python path


#17

@bradnywells, I think you need to add some context to your post. What does it do? What does it address?