Anaconda python not available from sudo
You almost got everything right. The only error is sudo echo $PATH
, where $PATH is substitued BEFORE being sent to sudo, so it's your user PATH not your "sudoed" PATH that's displayed.
Note that your sudo implementation and configuration may change the PATH variable, as I can read in a "man sudo" (found from the Internet as I don't have sudo):
PATH
May be overridden by the security policy.
So, in your "sudoed" PATH, there's probably no /anaconda/bin/
You may test this using sudo env | grep PATH
.
To allow or change the PATH environment variable in your sudoed environment, I only can direct you to your man sudo
, again: I'm not a sudo user.
The only thing I can drop you is sudo $(which python)
, as in sudo echo $PATH
, the $(which python)
will be executed by your user, resulting in /anaconda/bin/python
, so actually running sudo /anaconda/bin/python
which is another "solution".
To conclude, I should warn you that you probably don't want to run Python as root, there is almost no valid reason to do this, so your question is probably an XY problem: You got a first problem, you concluded by yourself it can be resolved by running Python as root, you tried sudo, got hit by sudo changing your PATH
, then posted your "2nd level" problem here. What is your "real problem" ? The one that triggered the "Hum, I should try with sudo" ?
Anaconda python not available from sudo
You almost got everything right. The only error is sudo echo $PATH
, where $PATH is substitued BEFORE being sent to sudo, so it's your user PATH not your "sudoed" PATH that's displayed.
Note that your sudo implementation and configuration may change the PATH variable, as I can read in a "man sudo" (found from the Internet as I don't have sudo):
PATH
May be overridden by the security policy.
So, in your "sudoed" PATH, there's probably no /anaconda/bin/
You may test this using sudo env | grep PATH
.
To allow or change the PATH environment variable in your sudoed environment, I only can direct you to your man sudo
, again: I'm not a sudo user.
The only thing I can drop you is sudo $(which python)
, as in sudo echo $PATH
, the $(which python)
will be executed by your user, resulting in /anaconda/bin/python
, so actually running sudo /anaconda/bin/python
which is another "solution".
To conclude, I should warn you that you probably don't want to run Python as root, there is almost no valid reason to do this, so your question is probably an XY problem: You got a first problem, you concluded by yourself it can be resolved by running Python as root, you tried sudo, got hit by sudo changing your PATH
, then posted your "2nd level" problem here. What is your "real problem" ? The one that triggered the "Hum, I should try with sudo" ?
sudo/conda/pip/PATH not found on Git Bash
You'll probably want to just run the regular windows installer (from the python site - https://www.python.org/downloads/) and then add the appropriate folder with the python
and pip
binaries to your $PATH system variable.
There are package managers like https://community.chocolatey.org/packages for windows, but as you can see they do not come as standard on windows.
How to run Anaconda Python on 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. 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
Python conda env does not contain local package when using sudo
Python (or Anaconda in your case) has few different environments on your computer, when installing packages as a user they are probably installed on ~/.local/python/...
and when installing as root they are installed on /var/lib/python/...
.
When you are running python as a user and importing a package it we'll look in several places including the local directory.
But when running python as root it won't look in these places..
The most simple solution is to install these packages using sudo
, or start using venv
which is highly more recommended.
Anaconda Sudo PIP permissions Problems
Most of the time, a sudo pip install
is almost never what you really want. While in some cases, it may "appear" to work and solve you're immediate problem. More often than not you've just broken your system python without knowing it.
In the context of that repo, I'd ignore the repo's README and do this.
$ git clone https://github.com/ghimiredhikura/Eye-Color-Detection
$ cd Eye-Color-Detection
Create a virtualenv environment, change yourenvname
as you like.
$ conda create -n yourenvname python=3.x
$ conda activate yourenvname
Install the dependencies and run the code
$ pip install -r requirements.txt
$ python3 eye-color.py --input_path=sample/2.jpg --input_type=ima
As fixing you conda environment may be difficult to debug depending on what else you've sudo
'd in attempting to resolve your issue. If you happen to be familiar with "regular" virtualenv's created using python's builtin virtual environment tooling, then you could also try this to get you going.
$ python3 -m venv .venv --copies
$ source .venv/bin/active
$ pip install -r requirements.txt
$ python3 eye-color.py --input_path=sample/2.jpg --input_type=image
Cannot install python wheel file in conda without sudo
I am using Python 3.7 in the conda environment and Python 3.6 outside.
This is the issue. You have a cp36
whl file, so python 3.6. I am suspecting that when you run sudo pip
, your systems pip
is invoked, whereas when you run pip
, then pip
from your conda env
is used, and cannot install a python 3.6 whl to a python 3.7 env.
Either you need to get the cp37
whl or create a conda env that has python 3.6 installed
Python 2.7, not Anaconda 3 running when I run as root using sudo
Your python version and installation location for root is different. If you want to use /opt/anaconda3/bin/python
, there are different ways:
You can add alias python="/opt/anaconda3/bin/python" to your .bashrc
file of root user and re login or source this .bashrc
.
Other way is to use #!/opt/anaconda3/bin/python
in your python code when you run it from root user so that is uses your anaconda distribution.
Point is, you have to use /opt/anaconda3/bin/python
as your python binary.
You mayalso remove python2.7
from your root user and add /opt/anaconda3/bin/python
in your PATH
env variable.
Also, you can add /opt/anaconda3/bin/python
in your PATH environment variable and use python3 instead of python from root user. or you can use /opt/anaconda3/bin/python
instead of python
Make sure the permissions and owner ship of paths are good without conflicts among users.
Related Topics
How to Load All Modules in a Folder
How to Base-64 Encode a Png Image for Use in a Data-Uri in a CSS File
Detect Log File Rotation (While Watching Log File for Modification)
How to Grab the Color of a Pixel on My Desktop? (Linux)
Opening a Python Thread in a New Console Window
Pipe Raw Opencv Images to Ffmpeg
Get Local Network Interface Addresses Using Only Proc
How to Find the Owner of a File or Directory in Python
Find Broken Symlinks with Python
How to Get the Last Day of the Month
How to Plot Multiple Dataframes in Subplots