PyDev: Fatal error Python32\lib\io.py, line 60, in <module> - python

I work in PyDev and quite suddenly, I cannot run my python programs from within Eclipse's PyDev (version 2.1.0) anymore.
Any python program I have ran through Run As > Python Run fails wioth
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
File "C:\Python32\lib\io.py", line 60, in <module>
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
I can still run my program in command Line, only Eclipse * I have only one version of Python (3.2)
I haven't changed my python files since last time they worked. They are encoded UTF-8.
I haven't upgraded Eclipse nor PyDev since last time they worked
Python is installed in c:\python32 (defined in the environment variable PYTHONPATH)
My XP system has been updated today for KB2536276 and
Any idea?

I have finally found out where the problem came from: I had a file called stat.py and this is apparently creating a conflict with Lib/stat.py
Unfortunately the error message was very obscure.
And I just don't understand why pyDev behaves differently than python.exe

Related

String syntax error occurring while switching from Windows Python to Linux Python

I am currently transitioning from running a python script just within a PyCharm anaconda environment to running it on a Linux (ubuntu) SFTP. Within this SFTP I've built the job file with all required packages and all modules seem to be installed properly.
I am having problems with random string syntax errors that did not exist before.
E.g this line
regFile = (f'{i}_{df.index[0].strftime("%Y%m%d")}-{df.index[-1].strftime("%Y%m%d")}_Model.gz')
Runs perfectly fine with no errors on Windows Python.
But when I run it within this Linux supercomputer, I get a syntax error on most strings, but nothing on the rest of the code.
File "./test.py", line 355
regFile = (f'{i}_{df.index[0].strftime("%Y%m%d")}-{df.index[-1].strftime("%Y%m%d")}_Model.gz')
^
SyntaxError: invalid syntax
Is this common to experience syntax errors transitioning between Windows and Linux? Any suggestions to fix this line of code to work for both?
Thanks!
Have tried ensuring all modules were downloaded properly in case it was a version issue with Python. Have unsuccessfully attempted switching the line slightly to work for both.

Running a tester file in the VSC terminal - ModuleNotFoundError

I have made a tester file to check my other files are implementing correctly, however I can only get an output by clicking run on the file (top right green arrow). When I type 'python Test.py' in the terminal I get :
Fatal Python error: initsite: Failed to import the site module
ModuleNotFoundError: No module named 'site'
Current thread 0x0000000102c0ce00 (most recent call first):
I assume this is an environment issue for my terminal? I am in the correct folder (one above Test.py).
Any ideas how I can change this?
Thanks!
It looks like the python interpreter you are taking when you run python Test.py in the terminal is different from the one when you click the Run Python File in Terminal(green triangle) button.
Could you type this command in the VSCode terminal(CMD: where python; Powershell: get-command python) to check which python you are using when you take python Test.py command to run your python file? And compare it with another one.

PyCares - Fatal Python error: PyImport_GetModuleDict: no module dictionary

I've been trying to get a script to run on a Windows server. It runs fine on my Mac, but keeps throwing an error at the end of the script. The output from the script is as expected and completes entirely, then this error is thrown:
Fatal Python error: PyImport_GetModuleDict: no module dictionary
Current thread 0x00001880 (most recent call first):
File "C:\Python37\lib\site-packages\pycares\__init__.py", line 387 in (lambda)
Currently I'm running Python 3.6.5 and getting this error but I've tried it up to Python 3.7.5 and get the same error. This seems like a Windows specific issue with Pycares since the same script runs fine on my Mac machine. Since the script executes correctly, even on windows, this seems like it is an error thrown in the cleanup of the script.
Any ideas on a cause or a workaround?
Edit: I've found this Python bug https://bugs.python.org/issue26153 that seems to say it's due to a race condition and warnings in the del function, but I still get the issue even when running Python 3.7

python library loads and works properly from command line, but 'ImportError: No module' if I try to run at boot

I’m trying to run a couple of python programs at boot time (in connection with some halloween costumes I’ve been making with my kids; I don’t want somebody to have to log in remotely to start the software in their costumes if they have to reboot for some reason).
The software works perfectly if run from the command line, whether launched from its own directory or any other. However if I try to run at launch by putting the script in rc.local, nothing happens and I log the following error:
Traceback (most recent call last):
File "/home/pi/sound.py", line 4, in <module>
from pad4pi import rpi_gpio
ImportError: No module named pad4pi
Additional information:
Some additional color: which python returns '/usr/bin/python’ and I have fully specified in rc.local that this is the python to use (/usr/bin/python /home/pi/sound.py &)
I installed with pip install pad4pi, and checking a moment ago it confirms that
pad4pi in ./.local/lib/python2.7/site-packages (1.1.5)
Why would the pad4pi library (which is needed in both projects I’m working on) be available from the command line but not at launch? And more importantly, what can I do about it?
[Note, solution below. I will accept the answer when stackOverflow lets me.]
The library was not appearing in $Pythonpath at boot time.
I added
export PYTHONPATH=$PYTHONPATH:/home/pi/.local/lib/python2.7/site-packages to my rc.local file, before it ran my python code, and all was well.

Why does the script package in atom not work with command but does manually?

I am using Windows 10, and Python 3.6 (installed at C:\Users\George\Anaconda3\python.exe). I have also installed Atom and am trying to use it as a python development environment with the script package.
An issue I consistently come across with is running my code using script. Checked other answers here but to no avail.
As an example, this is some code in a atom-test.py file:
import numpy as np
myArray = np.array([1,2,3,4])
print(np.sum(myArray))
When I run it using ctrl+b (I changed ctrl+shift+b to ctrl+b), I get this error:
Traceback (most recent call last):
File "C:\Users\George\atomtest1.py", line 1, in <module>
import numpy as np
ImportError: No module named 'numpy'
However, the module is imported because I can easily do this with terminal and it works fine.
Then I realized that manually running the script from profile by going to Package>Script>Run with profile then selecting the profile where python is set in the command (in my case Users/George/Anaconda3/python.exe) then it works fine.
10
[Finished in 0.793s]
So what can I do to get it to run there just by selecting ctrl+b?
I've encountered this problem many times. A workaround that works for me is to just keep trying to run the script and restart Atom. After a while, it kicks in and runs and all is fine. I know this answer sucks but it works for me. I just now ran into this problem. It started working on 3rd restart and continued for a while.

Categories