Posts: 2
Joined: Tue May 09, 2017 11:10 am

Two python 3 versions problem

Sun Jul 18, 2021 9:38 pm

I have a Rapberry Pi3 with python2, python 3.4 and python 3.7.4.
When I install a package with sudo apt-get python3, it is installed in the python3/dist-packages directory.
My python 3.4 has in sys.path the path to this directory, so when I import a module from 3.4 version it is ok.
sys.path of pyhton 3.4:
['', '/home/pi', '/usr/bin', '/usr/local/lib/python3.4/dist-packages/Adafruit_DHT-1.3.2-py3.4-linux-armv7l.egg', '/usr/local/lib/python3.4/dist-packages/WebIOPi-0.7.1-py3.4-linux-armv7l.egg', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-arm-linux-gnueabihf', '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']

Python 3.7 sys.path, hasn't the python3 path inside:
sys.path of python3.7.4
['', '/home/pi/Desktop', '/usr/local/bin', '/usr/local/lib/python37.zip', '/usr/local/lib/python3.7', '/usr/local/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/site-packages/pyserial-3.5-py3.7.egg']

So it happen that the import of some modules I already installed, just failed.

I think that I have just to add to sys.path in 3.7 version the python3/dist-packages path, but i want to do it permanently!
How can I do?

Posts: 143
Joined: Fri Aug 21, 2020 5:59 pm

Re: Two python 3 versions problem

Wed Jul 21, 2021 3:49 pm

Use virtual environments when working with different versions of python

https://realpython.com/python-virtual-e ... -a-primer/
https://www.geeksforgeeks.org/python-vi ... vironment/

There are many other links, just google "python virtual environment"

Posts: 18362
Joined: Tue Jul 17, 2012 3:02 pm

Re: Two python 3 versions problem

Wed Jul 21, 2021 10:13 pm

Save yourself. Switch to a more stable language. Or at least one that has backward compatibility in mind.
Memory in C++ is a leaky abstraction .

Return to “Python”