如何在sudo上运行Anaconda Python [英] How to run Anaconda Python on sudo

查看:1020
本文介绍了如何在sudo上运行Anaconda Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前使用AWS在机器学习项目上运行一些测试.我想在没有互联网的情况下(通过root用户)运行Python脚本,因为互联网带宽非常有限.我尝试通过这样做来运行convnets.py脚本

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

但是那是行不通的,因为Anaconda不使用PYTHONPATH,这使得root无法找到Anaconda Python环境.因此会引发无法导入"和找不到模块"之类的错误.

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.

我该如何设置才能让Anaconda和sudo一起公平竞赛?

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

推荐答案

由于使用sudo与典型环境使用的PATH不同,因此需要确保指定要使用Anaconda的python解释器,而不是系统python.您可以使用以下命令检查正在运行的是哪一个

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

要解决此问题,并指向Anaconda的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

如果执行此操作,则应该可以访问anaconda管理的所有模块.

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

conda create --name $ENVIRONMENT_NAME python

您可以在运行命令之前将其激活

You can activate it prior to running your command

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

这篇关于如何在sudo上运行Anaconda Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆