Python Forum
I seem to have two versions of python 3.7.9 installed - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: I seem to have two versions of python 3.7.9 installed (/thread-31078.html)



I seem to have two versions of python 3.7.9 installed - miner_tom - Nov-21-2020

I am not aware of how this happened but the two versions give different results.

When I invoke python the results are

Quote:Python 3.7.9 (default, Aug 18 2020, 06:22:45)
[GCC 7.5.0] on linux

When I invoke python3 the results are

Quote:Python 3.7.9 (default, Aug 31 2020, 12:42:55)
[GCC 7.3.0] :: Anaconda, Inc. on linux

Evidently, the python3 invokes python attached somehow to anaconda, which is what I want. When I then import packages such as numpy, etc, they successfully import.

When I invoke python no python3, I can not successfully import any of my python installed packages.

What is going on?

Thank You
Tom


RE: I seem to have two versions of python 3.7.9 installed - buran - Nov-21-2020

(Nov-21-2020, 07:54 AM)miner_tom Wrote: What is going on?
miner_tom Wrote:I seem to have two versions of python 3.7.9 installed

I think you answered your question in the title and the packages are installed just for one of the interpreters (the anaconda distribution)


RE: I seem to have two versions of python 3.7.9 installed - miner_tom - Nov-21-2020

(Nov-21-2020, 08:00 AM)buran Wrote:
(Nov-21-2020, 07:54 AM)miner_tom Wrote: What is going on?
miner_tom Wrote:I seem to have two versions of python 3.7.9 installed

I think you answered your question in the title and the packages are installed just for one of the interpreters (the anaconda distribution)

I appreciate your response! Thank you. But, if I could get just a bit of clarification I might better learn about packages. For example, you wrote that the packages are installed for just the anaconda distribution, and that makes sense and is correct, since I did install them using conda (I guess, that is how it happened). But, how could I install packages for the non anaconda installation of python 3.7?

Thank You again.
Tom


RE: I seem to have two versions of python 3.7.9 installed - snippsat - Nov-21-2020

(Nov-21-2020, 06:43 PM)miner_tom Wrote: But, how could I install packages for the non anaconda installation of python 3.7?
As python point to your Python 3.7 Linux version.
python -m pip install requests  # may need pip3  
Test with pip -v or pip3 -V and see where it point point at,this it where it install to.
If need install.
sudo apt install python3-pip

Also with Anaconda you should activate (base) environment,then conda and pip always point to Anaconda.
conda activate base



RE: I seem to have two versions of python 3.7.9 installed - miner_tom - Nov-22-2020

I apologize, but I do not understand. I installed requests but have no idea what to use it for. Looking at the documentation is says that it is "HTTP for humans".

I have pip and use pip -v and that just brings up a list of commands that I can use with pip. pi -V shows the version of python that it points to, which is python 3.7

I still do not know the difference between what typing "python" and typing "python3" is. Or, to where does each one point?

Thank You
Tom


RE: I seem to have two versions of python 3.7.9 installed - Gribouillis - Nov-22-2020

You can ask python to where it points. For example in my kubuntu 16.04,
λ python3
Python 3.5.2 (default, Oct  7 2020, 17:19:02) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/usr/bin/python3'
By the way, what about installing packages from within Python itself? You would be certain that they are installed for the current interpreter.
import subprocess as sp
import sys

def install_package(name):
    sp.call([sys.executable, '-m', 'pip', 'install', '-U', '--user', name])


if __name__ == '__main__':
    install_package('requests')



RE: I seem to have two versions of python 3.7.9 installed - snippsat - Nov-22-2020

(Nov-22-2020, 09:11 AM)miner_tom Wrote: I apologize, but I do not understand. I installed requests but have no idea what to use it for. Looking at the documentation is says that it is "HTTP for humans".
It was just demo to see it works,Requests is used instead of urllib.
Can also uninstall with pip.
python -m pip uninstall requests
# Or just pip as it point to 3.7 for you
pip uninstall requests
To do the same as Gribouillis from command line.
python -c "import sys; print(sys.executable)"
Quote:I still do not know the difference between what typing "python" and typing "python3" is. Or, to where does each one point?
In older distors did python(point to Python 2) and python3(to Python 3).
With new distros is like Ubuntu/Mint 20 then Python 2 removed,and python always point to Python 3.
As python point to 3.7 for you then it's okay.

To use Anaconda activate (base),then python and pip will point to Anaconda.
conda activate base



RE: I seem to have two versions of python 3.7.9 installed - miner_tom - Nov-22-2020

(Nov-22-2020, 09:56 AM)Gribouillis Wrote: You can ask python to where it points. For example in my kubuntu 16.04,
λ python3
Python 3.5.2 (default, Oct  7 2020, 17:19:02) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/usr/bin/python3'
By the way, what about installing packages from within Python itself? You would be certain that they are installed for the current interpreter.
import subprocess as sp
import sys

def install_package(name):
    sp.call([sys.executable, '-m', 'pip', 'install', '-U', '--user', name])


if __name__ == '__main__':
    install_package('requests')

Wow, I think that with your help I have finally figured out what is going on. Perhaps you can check my logic/reasoning.

Outside of a virtual environment:
pip -V
Quote:pip 20.2.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
$python
Quote:Python 3.7.9 (default, Aug 18 2020, 06:22:45)
[GCC 7.5.0] on linux
>>> import sys
>>> sys.executable
'/usr/bin/python3.7'

So, as shown in the above, packages are put into /usr/local/lib/python3.6 and a python3.7 executable is called. Ok, I can see how that the dis-packages might not be executed by a different executable.

Next case is calling python3
$python3
Quote:Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
>>> import sys
>>> sys.executable
'/usr/bin/python3'
lrwxrwxrwx 1 root root 9 Mar 3 2019 python3 -> python3.6

A python3.6 executable is able to run the packages in /usr/local/lib/python3.6. That would make sense.

So now, lets go into the python virtual environment that I set up with anaconda.

conda activate pytorchbook
(pytorchbook)$pip -V
Quote:pip 20.2.4 from ~/anaconda3/envs/pytorchbook/lib/python3.7/site-packages/pip (python 3.7
Packages in this environment are in a different place that in the cases outside of the environment.

Entering python:
$python
Quote:Python 3.7.9 (default, Aug 18 2020, 06:22:45)
[GCC 7.5.0] on linux
>>> import sys
>>> sys.executable
'/usr/bin/python3.7'

In this case, the same executable is called inside and outside of the virtual environment. And, I am NOT able to import modules from ~/anaconda3/envs/pytorchbook/lib/python3.7.

Last case, entering python3 from inside the virtual environment:
Quote:Python 3.7.9 (default, Aug 31 2020, 12:42:55)
[GCC 7.3.0] :: Anaconda, Inc. on linux
>>> import sys
>>> sys.executable
'~/anaconda3/envs/pytorchbook/bin/python3'

So, the python3 executable from within the pytorch environment can be used to import modules from within ~/anaconda3/envs/pytorchbook/lib/python3.7

Not sure of why two python executables of python 3.7.9 don't behave the same other than the fact that they were compiled under different versions of GCC as shown.

Does the above make sense?

Thank you for all of your help.

Tom