How to run Anaconda Python on sudo

半城伤御伤魂 提交于 2020-05-14 09:43:23

问题


Currently using AWS to run some tests on a machine learning project. I would like to run Python scripts without internet (via root) because the internet bandwidth is extremely limited. I try to run the convnets.py script by doing

sudo python convnets.py >> output

But that does not work, as Anaconda does not use PYTHONPATH, making it impossible for root to find the Anaconda Python environment. So errors like "cannot import" and "module not found" are thrown.

How do I set this up so I can get Anaconda and sudo to play fair together?


回答1:


Because using sudo uses a different PATH than your typical environment, you need to be sure to specify that you want to use Anaconda's python interpreter rather than the system python. You can check which one is being run with the following command

sudo which python

To fix this, and point to Anaconda's python interpreter, specify the full path to the correct interpreter.

sudo /path/to/anaconda/bin/python convnets.py >> output

If you do this, you should be able to access all of the modules managed by anaconda.

On the other hand, if you have an Anaconda environment created

conda create --name $ENVIRONMENT_NAME python

You can activate it prior to running your command

sudo source activate $ENVIRONMENT_NAME && python convnets.py >> output


来源:https://stackoverflow.com/questions/36659448/how-to-run-anaconda-python-on-sudo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!