Reise45
Reise45

Reputation: 1203

Sudo does not find new python version

I had python2.6 on my linux box but installed python3.4 to use new modules. I installed it using sudo access. The new version was installed in /usr/local/bin. Without root access, I can use the new python3.4, both by just using python3.4 in the command line or using the shebang in the .py file #!/usr/local/bin/python3

Now I am trying to install a module, for which I need sudo access. When I am root, and I run python3.4, it says command not found. I ran whereis python and found the path to python2.6 in /usr/bin, but whereis python3.4 as root gives, not found in /usr/bin, which is correct since it is in /usr/local/bin. Again, if I exit from root, I have no trouble using python3.4

This seems like a $PATH issue (not sure), can some one help me what I am doing wrong while installing the module for the new python3.4? I was able to install the module, but it was installed in the old python2.6 site-packages.

Upvotes: 6

Views: 12040

Answers (4)

Tharzeez
Tharzeez

Reputation: 1343

You can get the python PATH by using this command whereis python

and to run with sudo permission you can use sudo /usr/local/bin/python3.10 filename.py

In my case it was in /usr/local/bin/python3.10

Upvotes: 0

JoErNanO
JoErNanO

Reputation: 2488

The pithonic way to go about handling multiple-interpreters and multiple-library coexistence is by using virtual environments. These allow you to create a dedicated Python workspace in which you can install the libraries, and the interpreter needed for a given project. In this way you keep projects, and their dependencies, separated and avoid having to do horrific things like symbolic links to executables forced into your path. Moreover by creating a virtual environment in a directory where you have full access rights will not require you to be root, or sudo, to install packages and such.

Upvotes: 0

superK
superK

Reputation: 3972

How about export PATH+=:/usr/local/bin, try it, maybe helpful.

Upvotes: 8

iamkhush
iamkhush

Reputation: 2592

Well you could have given the location to install Py 3.4 to be in /usr/bin.

An easy approach could be to copy the Py 3.4 bin to /usr/bin from /usr/local/bin.

Secondly You can also install again with the prefix params.

Upvotes: 2

Related Questions