[英]How to run Anaconda Python on sudo
Currently using AWS to run some tests on a machine learning project. 当前使用AWS在机器学习项目上运行一些测试。 I would like to run Python scripts without internet (via root) because the internet bandwidth is extremely limited.
我想在没有互联网(通过root用户)的情况下运行Python脚本,因为互联网带宽非常有限。 I try to run the convnets.py script by doing
我尝试通过运行convnets.py脚本
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. 但这是行不通的,因为Anaconda不使用PYTHONPATH,这使得root无法找到Anaconda Python环境。 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? 我该如何设置才能让Anaconda和sudo一起公平竞赛?
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. 因为使用
sudo
使用的PATH
不同于典型环境,所以您需要确保指定要使用Anaconda的python解释器而不是系统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. 要解决此问题,并指向Anaconda的python解释器,请指定正确解释器的完整路径。
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. 如果这样做,您应该能够访问anaconda管理的所有模块。
On the other hand, if you have an Anaconda environment created 另一方面,如果您创建了Anaconda环境
conda create --name $ENVIRONMENT_NAME python
You can activate it prior to running your command 您可以在运行命令之前将其激活
sudo source activate $ENVIRONMENT_NAME && python convnets.py >> output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.