Python Forum
I seem to have two versions of python 3.7.9 installed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I seem to have two versions of python 3.7.9 installed
#1
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
Reply
#2
(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)
miner_tom likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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
Reply
#4
(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
miner_tom likes this post
Reply
#5
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
Reply
#6
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')
miner_tom likes this post
Reply
#7
(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
miner_tom likes this post
Reply
#8
(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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Launcher (on Windows) only necessary when 2 or more Python versions installed? pstein 1 265 Feb-17-2024, 12:43 PM
Last Post: deanhystad
Question log.exception() without arguments in old Python versions? cthart 5 1,117 Nov-19-2022, 07:09 PM
Last Post: Gribouillis
  Python versions with libexpat fixes raghupcr 5 2,363 Feb-24-2022, 06:26 PM
Last Post: raghupcr
  Installed versions of Python SamHobbs 5 2,463 Sep-02-2021, 02:28 PM
Last Post: jefsummers
  Different versions of Python3 and Python Led_Zeppelin 2 2,268 Jun-16-2021, 05:31 AM
Last Post: snippsat
  Python Versions ThatTamyBot 2 2,658 Mar-11-2021, 11:27 AM
Last Post: ThatTamyBot
  pip list to show all versions of a package installed pvbadiger05b 4 2,430 May-21-2020, 06:48 PM
Last Post: jameshonest
  Package installed through Anaconda "not found" by Python zonova 0 2,256 May-08-2020, 11:50 PM
Last Post: zonova
  How to change directory to any folder where python is not installed ? firashelou 4 2,572 Apr-03-2020, 02:43 PM
Last Post: firashelou
  Is Python Installed? DaveMc 6 2,941 Jan-26-2020, 08:31 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020