Python Forum
python2 python3 messed up : How to fix ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python2 python3 messed up : How to fix ?
#1
Hi

I'm running Mint20 and am presently trying to follow a specific procedure that, I think, uses python 2 or python3 but is detecting some error in my python installation.
It could be possible as I previoulsy ran sudo apt install python-is-python3 /or made some modification to try something working some time ago...(making some alaises or simlink)

Here is the entire error I get that makes me thinking there are some python2/3 messed up :
"~/SBMS_update/electrodacus-esp32$ platformio run Processing serial (platform: https://github.com/platformio/platform-espressif32.git; board: nodemcu-32s; framework: arduino, espidf) Verbose mode can be enabled via -v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/...u-32s.html
PLATFORM: Espressif 32 (2.1.0+sha.a58a358) > NodeMCU-32S
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

framework-arduinoespressif32 0.0.0+sha.d011dd7
framework-espidf 3.40001.200521 (4.0.1)
tool-cmake 3.16.4
tool-esptoolpy 1.30000.201119 (3.0.0)
tool-ninja 1.7.1
tool-openocd-esp32 2.1000.20201202 (10.0)
toolchain-esp32ulp 1.22851.191205 (2.28.51)
toolchain-xtensa32 2.80200.200827 (8.2.0)
Traceback (most recent call last):
File "genVersion.py", line 1, in
import subprocess
File "/usr/lib/python3.8/subprocess.py", line 49, in
import signal
File "/usr/lib/python3.8/signal.py", line 3, in
from functools import wraps as _wraps
File "/usr/lib/python3.8/functools.py", line 18, in
from collections import namedtuple
File "/usr/lib/python3.8/collections/init.py", line 27, in
from reprlib import recursive_repr as _recursive_repr
File "/home/harold/.local/lib/python2.7/site-packages/reprlib/init.py", line 7, in
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.8/re.py", line 127, in
import functools
File "/usr/lib/python3.8/functools.py", line 18, in
from collections import namedtuple
File "/usr/lib/python3.8/collections/init.py", line 27, in
from reprlib import recursive_repr as _recursive_repr
File "/home/harold/.local/lib/python2.7/site-packages/reprlib/init.py", line 7, in
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.

Original exception was:
Traceback (most recent call last):
File "genVersion.py", line 1, in
import subprocess
File "/usr/lib/python3.8/subprocess.py", line 49, in
import signal
File "/usr/lib/python3.8/signal.py", line 3, in
from functools import wraps as _wraps
File "/usr/lib/python3.8/functools.py", line 18, in
from collections import namedtuple
File "/usr/lib/python3.8/collections/init.py", line 27, in
from reprlib import recursive_repr as _recursive_repr
File "/home/harold/.local/lib/python2.7/site-packages/reprlib/init.py", line 7, in
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
OSError: 'python genVersion.py' exited 1:
File "/home/harold/.local/lib/python2.7/site-packages/platformio/builder/main.py", line 170:
env.SConscript("$BUILD_SCRIPT")
File "/home/harold/.platformio/packages/tool-scons/script/../engine/SCons/Script/SConscript.py", line 541:
return _SConscript(self.fs, *files, **subst_kw)
File "/home/harold/.platformio/packages/tool-scons/script/../engine/SCons/Script/SConscript.py", line 250:
exec file in call_stack[-1].globals
File "/home/harold/.platformio/platforms/espressif32/builder/main.py", line 224:
target_elf = env.BuildProgram()
File "/home/harold/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 224:
return self.method(*nargs, **kwargs)
File "/home/harold/.local/lib/python2.7/site-packages/platformio/builder/tools/platformio.py", line 61:
env.ProcessProgramDeps()
File "/home/harold/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 224:
return self.method(*nargs, **kwargs)
File "/home/harold/.local/lib/python2.7/site-packages/platformio/builder/tools/platformio.py", line 124:
env.ProcessFlags(env.get("BUILD_FLAGS"))
File "/home/harold/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 224:
return self.method(*nargs, **kwargs)
File "/home/harold/.local/lib/python2.7/site-packages/platformio/builder/tools/platformio.py", line 222:
env.Append(**env.ParseFlagsExtended(flags))
File "/home/harold/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 224:
return self.method(*nargs, **kwargs)
File "/home/harold/.local/lib/python2.7/site-packages/platformio/builder/tools/platformio.py", line 185:
for key, value in env.ParseFlags(str(raw)).items():
File "/home/harold/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 810:
do_parse(arg)
File "/home/harold/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 676:
arg = self.backtick(arg[1:])
File "/home/harold/.platformio/packages/tool-scons/script/../engine/SCons/Environment.py", line 594:
raise OSError("'%s' exited %d" % (command, status))
========================================== [FAILED] Took 0.37 seconds ==========================================

Environment Status Duration
serial FAILED 00:00:00.368
==================================== 1 failed, 0 succeeded in 00:00:00.368 ===================================="

My quetsion is : How could I fix to a proper installation of both python2 and python3 ?
Reply
#2
Can you run the following code in python 3.8 and post the output here?
>>> import os, sys
>>> print(sys.path)
>>> for k, v in os.environ.items():
...     if 'PY' in k:
...        print(k, repr(v))
>>>
Reply
#3
Hi and thanks you for caring for my problem.

Here is the output :
$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys
>>> print(sys.path)
['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/harold/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.8/dist-packages']
>>> for k, v in os.environ.items():
...     if 'PY' in k:
...         print(k, repr(v))
... 
>>> 
>>> 
Reply
#4
The strange thing in your error message is this
Error:
File "/usr/lib/python3.8/collections/init.py", line 27, in from reprlib import recursive_repr as _recursive_repr File "/home/harold/.local/lib/python2.7/site-packages/reprlib/init.py", line 7, in
When the standard module 'collections' from python 3.8 library tries to import the stardard module 'reprlib', it imports it from /home/harold/.local/lib/python2.7/site-packages, that is to say from the python 2.7 library insteado of importing it from python 3.8's library. For me it means that at this moment, the directory /home/harold/.local/lib/python2.7/site-packages is mistakenly in the sys.path list.

I suggest that at the very top of genVersion.py, you add temporarily this line to see what sys.path contains when this line is executed. Then see if it contains a python 2.7 directory
import sys
raise RuntimeError(sys.path)
bowlofred likes this post
Reply
#5
Sorry, I'm not sure what you're asking for me to do ?

$ python
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> raise RuntimeError(sys.path)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: ['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/harold/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.8/dist-packages']
>>> 
Reply
#6
Write this in the file named genVersion.py
Reply
#7
here is part of the result where indeed a "/.local/lib/python2.7/site-packages" appears !

Traceback (most recent call last):
  File "genVersion.py", line 2, in <module>
    raise RuntimeError(sys.path)
RuntimeError: ['/home/harold/SBMS_update/electrodacus-esp32', '/home/harold/.local/lib/python2.7/site-packages', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/harold/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.8/dist-packages']
Error in sys.excepthook:
Reply
#8
Now we see where the error comes from. The directory '/home/harold/.local/lib/python2.7/site-packages' shouldn't be in sys.path. The question now is to understand how it arrived there. How was genVersion.py executed? Did some other program launch it? Also how did '/home/harold/SBMS_update/electrodacus-esp32' arrive in sys.path?
Reply
#9
I don't really know.

As I got some problem some time ago, I tried different things, but don't really remember what.

I was presentlty following that procedure :
https://github.com/armageddon421/electrodacus-esp32

Homestly, Im' absolutely lost and discourage with python which always turn to be a nightmare to use with these version 2 and 3 ...
Sorry for being so negative.
Reply
#10
It is not a nightmare any more. The only thing to remember is to not use Python 2.7 or to have an operating system where Python 2.7 is not installed.

If I understand well, you followed the instructions here https://github.com/armageddon421/electrodacus-esp32 to install platformio and in these instructions there was the following command
Output:
pip install -U platformio
Unfortunately, my guess is that the 'pip' command that you used was that of python 2.7.

Here is my suggestion
  1. Run the command pip uninstall platformio
  2. Then run the command python3.8 -m pip install -U platformio
  3. Then run the command platformio update
Then see if it works better. It should as platformio's page on pypi is compatible with python 3 https://pypi.org/project/platformio/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Sad Migrating of python2 script to python3 zuri 7 989 Oct-05-2023, 02:40 PM
Last Post: snippsat
  Migration of Python2 and Python3 using Modernize and Future Rakshan 5 2,533 Oct-05-2023, 08:55 AM
Last Post: zuri
  Text Order is Kinda Messed Up? Prithak 0 1,044 Feb-03-2022, 04:00 PM
Last Post: Prithak
  Getting a small Python2 prog to run in Python3 steve140 4 3,895 Apr-19-2020, 09:27 AM
Last Post: steve140
  output mismatching when porting a python from python2 env to python3 env prayuktibid 2 2,571 Jan-21-2020, 04:41 AM
Last Post: prayuktibid
  python3 decoding problem but python2 OK mesbah 0 1,808 Nov-30-2019, 04:42 PM
Last Post: mesbah
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,920 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  Trying to run a python2 script dagamer1991 3 2,556 Aug-12-2019, 12:33 PM
Last Post: buran
  I think I messed up python.... XavPro_QC 7 14,128 Aug-02-2019, 09:02 PM
Last Post: XavPro_QC
  python2.7 executables thus the system python2.7 was erroring utility.execute()? vivekm 1 1,763 May-20-2019, 11:24 AM
Last Post: vivekm

Forum Jump:

User Panel Messages

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