简体   繁体   中英

How can I activate another user's conda environment?

a colleague of mine has written a python script that I need to use, which is called within a shell script. It produces plots with matplotlib. However, when I try to run his script, it fails in matplotlib commands with "ImportError: No module named PyQt4". The python script is called within the shell script with a syntax like

./script.py

script.py begins with a line to specify the python exec to use from within his miniconda environment, like

#!/user/miniconda/envs/py27/bin/python

I think the problem is that the code uses the default PyQt on my system when I run this command. I tried running script.py with the python exec in his environment, but this gives the same error. This also occurs if I try to run the script on his computer when logged into my account. Is there a way that I can run this script as if I were my colleague within my account?

Have your colleague generate a yaml file with his environment dependencies, then create a copy of his environment on your computer to run the script.

# your coworker runs:
conda env export -n [name of his environment] > environ.yml

Once you get yaml file, you can run

conda env create -f environ.yml

to copy the environment. From there, activate it and run the script

# on Windows
activate [environment name]
python ./script.py

# on *nix
source activate [environment name]
python ./script.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM