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
#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


Messages In This Thread
RE: I seem to have two versions of python 3.7.9 installed - by miner_tom - Nov-22-2020, 06:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Installing mailjet_rest for Python 3 while Python 2 is installed gw1500se 0 103 Jun-12-2024, 06:23 AM
Last Post: gw1500se
  Python Launcher (on Windows) only necessary when 2 or more Python versions installed? pstein 1 455 Feb-17-2024, 12:43 PM
Last Post: deanhystad
Question log.exception() without arguments in old Python versions? cthart 5 1,320 Nov-19-2022, 07:09 PM
Last Post: Gribouillis
  Python versions with libexpat fixes raghupcr 5 2,745 Feb-24-2022, 06:26 PM
Last Post: raghupcr
  Installed versions of Python SamHobbs 5 2,689 Sep-02-2021, 02:28 PM
Last Post: jefsummers
  Different versions of Python3 and Python Led_Zeppelin 2 2,427 Jun-16-2021, 05:31 AM
Last Post: snippsat
  Python Versions ThatTamyBot 2 2,786 Mar-11-2021, 11:27 AM
Last Post: ThatTamyBot
  pip list to show all versions of a package installed pvbadiger05b 4 2,671 May-21-2020, 06:48 PM
Last Post: jameshonest
  Package installed through Anaconda "not found" by Python zonova 0 2,397 May-08-2020, 11:50 PM
Last Post: zonova
  How to change directory to any folder where python is not installed ? firashelou 4 2,730 Apr-03-2020, 02:43 PM
Last Post: firashelou

Forum Jump:

User Panel Messages

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