1

I'm a complete novice as far as python is concerned, but need to install it for PlatformIO. I installed python-3.8.5-amd64.exe on Windows 10 and installed PlatformIO in VSCode. But when I try to do a build I get:

Fatal Python error: init_sys_streams: can't initialize sys standard streams
Traceback (most recent call last):
  File "C:\Program Files\Python38\lib\io.py", line 54, in <module>
ImportError: cannot import name 'open_code' from 'io' (unknown location)

Since io.py is installed as part of the python installation, I assume the 'open_code' symbol should be installed. Running the Repair option from python-3.8.5-amd64.exe and rebooting claims everything's fine, but it still fails.

Can someone explain, in simple terms, what I need to do to fix this?

Note: there's an answer here which indicates it's due to there having been 2 versions of python installed and that something's pointing at the wrong verison, but it doesn't explain how to fix it in any way that I understand (as well as being for a Linux installation).

Thanks.

StarNamer
  • 480
  • 6
  • 24
  • Please [edit] your post and add a [mre] to demonstrate the problem. We can't help without seeing the code that's causing the error. – MattDMo Sep 14 '20 at 22:46
  • Also... you didn't happen to name your python file `io.py`, did you? – MattDMo Sep 14 '20 at 22:47
  • That's what the traceback is supposed to look like... – MattDMo Sep 14 '20 at 22:48
  • @MattDMo OK, so it's the Marlin firmware that I'm trying to build. I haven't edited any python files except to confirm that line 54 of io.py is an import. This worked yesterday, but then I realised I had a 32-bit version of python installed which caused other problems, so I uninstalled it and tried installing the 64-bit version. As I said, I'm a complete python novices, so have no idea how to produce a "minimal reproducible example". I'm assuming this is an installation problem and someone will know which environment variable or registry setting didn't get cleaned up when I uninstalled. – StarNamer Sep 14 '20 at 22:58
  • Have you rebooted since you uninstalled the 32-bit version and installed the 64-bit one? That works wonders sometimes. – MattDMo Sep 14 '20 at 23:02
  • If that doesn't work, try checking your environment variables for `PYTHONPATH`, and if present what its value is. – MattDMo Sep 14 '20 at 23:03
  • to save u lots of headaches, uninstall everything, reboot ur comp and reinstall everything, then tell us if its successful. –  Sep 14 '20 at 23:05
  • @StarNamer I recommend you to use a python package manager like [Anaconda](https://www.anaconda.com/products/individual#Downloads) sometimes packages won't install properly on windows due to non-compatible built-packages. Also, it gives you the chance to run multiple instances of different python versions. – Souhailhimself Sep 14 '20 at 23:19
  • @MattDMo Yes, at least twice! – StarNamer Sep 14 '20 at 23:35
  • @CYREX Unistalling both python and platformio and rebooting didn't help because, it seems, platformio doesn't actually remove everything. So on a reinstall, it just puts everything back the way it was before. – StarNamer Sep 14 '20 at 23:37
  • @Souhailhimself I don't want to run/use any python packages. The only reason to install python was because PlatformIO uses it. Although it's a popular language, I have no desire to add it to my list of known languages (I've been programming for 45 years and the list is long) and I don't intend writing anything in it. – StarNamer Sep 14 '20 at 23:40

1 Answers1

1

The solution was to delete the .platformio folder from my user folder. Obviously, PlatformIO was 'remembering' the previous python install and confusing things!

StarNamer
  • 480
  • 6
  • 24
  • That worked for me as well. Once. When I made a couple of changes to Marlin and tried to rebuild, the problem was back. Was this a permeant fix for you? – casterle Oct 12 '20 at 22:53
  • I think I found a poor work-around. Platformio was finding my Python 3.8 installation (which was on my path). I suspected that was the problem after seeing that the same was happening to you. Renaming the Python 3.8 folder (as a quick fix so it's contents were no longer on the path) fixed the issue. This, of course, will probably narf something else that needed to find that version of Python. – casterle Oct 12 '20 at 23:21
  • @casterle I haven't had a problem since (more than a month) so, in that sense, it has been a 'permanent' fix. – StarNamer Oct 15 '20 at 07:32
  • I think you're right. I have this error and solved by just deleting any python folder inside .platformio folder. I just guess that will appear again if platformio is updated. – Hamza Hajeir Dec 02 '20 at 08:33