As usual, I opened Notepad++ and wrote my python code. Then when I opened my CMD to execute it, I got this error
`Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "C:\Users\pc\AppData\Local\Programs\Python\Python38-32\Lib\site.py", line 73, in <module>
import os
ModuleNotFoundError: No module named 'os'
I uninstalled and reinstalled python hoping that it'll run, but it didn't. Can anybody please help!
EDIT: Python doesn't work on my pc. Whenever I type "python" in the CMD, it would throw this error, IDLE is also not opening. And yes, my python is added to PATH so please don't say to add it to the path.
Try to run this snippet
import os
output = os.environ['HOME']
print(output)
If this is not working then there is issue with your python installation. You need to re-install it.
To get comfortable with python modules you can learn from here
Related
The skopt package (https://scikit-optimize.github.io/stable/install.html) was installed on a cluster I use.
When I run the code in python directly in the terminal (i.e., cluster terminal), no problem occurs and the code works as expected.
However when I simply place the command to execute the code in a PBS queue system file (e.g., python3 ./code.py), I cannot load the installed package and I get the following message:
Traceback (most recent call last):
File "./test.py", line 22, in <module>
from skopt import gp_minimize
ModuleNotFoundError: No module named 'skopt'
Could someone give me an insight on how to solve the problem?
If I need to provide any more information, let me know.
ps1: the packages is installed on /usr/local/lib/python3.6/site-packages/skopt directory.
ps2: I tried to load export PYTHONPATH=$PYTHONPATH:[$HOME]/.usr/local/lib/python3.6/site-packages/skopt into the PBS file and it didn't work.
This has happened to me before but its a pretty simple fix
pip3 converts to python3
pip converts to python
Use those commands instead of random. Check my comment for further details.
The solution was easier than I thought, as the skopt package was in the path "/usr/local/lib/python3.6/site-packages/" just use the command "export PYTHONPATH=$PYTHONPATH:/usr/local/ lib/python3.6/site-packages", before running the code in python
I was using the "export" command wrongly.
I'm trying to bundle my script into a .app using Tkinter as the GUI and the wrapper that does the bundling is Platypus.
I'm getting this error when I go to run the app.
Traceback (most recent call last):
File "/Users/samb/Desktop/Beta1.app/Contents/Resources/script", line 4, in <module>
import tkinter
File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/P...ework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
I'm running Python 3.7.4 on this machine, and my script uses:
import tkinter
from tkinter import filedialog
which should make it compatible. The script works when I run it using terminal, just not when I run the app.
I've specified in the bundling app that it should use python3 as well...
Not sure what I'm doing wrong here?
Several problems: There is no file at /usr/bin/python3. Either use /usr/local/bin/python3 or /usr/bin/env with python3 as args. Or whatever your particular python environment needs.
For some reason, python is looking for the library inside Xcode, which is unusual. I have python3 installed and there's no python in
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/
On my installation, the valid filepath is:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py
(i.e. in /Library, not inside Xcode.) As the script works in Terminal, it's likely that Platypus's config is wrong somehow.
As a quick hack, I suppose you could symlink Python.framework from /Library/Frameworks to the Frameworks folder inside Xcode.
As stated in the comments, you don't need to include the first import line. Currently, you're importing all of tkinter, and then importing just the filedialog. The whole point of from is to avoid importing the entire library.
I created an application in Python 3.6 with a GUI built in PyQt5. Some modules are only available for Python 3.5 and 3.6.
I managed to pack it on Mac using py2app. I am trying to do the same thing on Windows. I tried to use this guide, but I still have issues.
For what I understand I have 3 options:
py2exe
pyinstaller
cx_Freeze
1) py2exe
According to here py2exe is still not available for python3.6, I need to use python3.5 then.
Using 3.5, I get this error and the compilation stops:
error: [Errno 2] No such file or directory: 'C:\\Users\\carlo\\AppData\\Roaming\\Python\\Python35\\site-packages\\py2exe\\run-py3.5-win32.exe'
2) pyinstaller
Running pyinstaller through Python3.5 as:
pyinstaller --onefile APP.py
I get just a bunch of warnings (lib not found) but the compilation gets to the end. The created EXE, though, opens the command prompt and pops up the following error:
Traceback (most recent call last):
File "site-packages\PyInstaller\loader\rthooks\pyi_rth_qt5plugins.py", line 46, in <module>
File "c:\program files (x86)\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 573, in load_module
module = loader.load_module(fullname)
ImportError: DLL load failed: %1 is not a valid Win32 application.
Failed to execute script pyi_rth_qt5plugins
3) cx_Freeze
Using python3.5, it first give the 'TCL_LIBRARY' error. Following the instructions here the compilation goes smoothly. The created application, however, opens up and closes immediately. It simply doesn't work.
Using python3.6, the compilation seems okay. When I try to open the application, this error pops up. I just managed to take a quick screen-shot:
Does anybody have any suggestion? Any alternative I am not considering?
I managed to solve the problem!
I followed the instructions here.
I first ran (with Python3.5):
pyinstaller CodeName.py
Then I modified the .spec file as indicated in the link and the magic happened!
I'm on Windows using Python version 3.4.2. My Matplotlib is not importing in my file when I run it in the cmd, but it seems to work when I import from the python shell. I'm not sure if my path is messed up somehow. Whenever I run it in the cmd, it produces the following error:
F:\pypractice> py montecarlo.py
Traceback (most recent call last>:
File "montecarlo.py", line 2, in <module>
import matplotlib
ImportError: No module named matplotlib
Again, it works in the python shell, so it probably is a PATH problem. The path I have in my environment variables is F:\Python34\;F:\Python34\Scripts\; I was told to install the following modules: numpy, pyzt, dateutill, setuptools, and six. This fixed the importing error in the python shell.
All of my modules are placed in F:\Python34\Lib\site-packages.
Any help with fixing this problem would be greatly appreciated. Thank you.
I was messing with the wrong variable. Simply placing #!/usr/bin/env python at the top of my file fixed the problem.
I am a python Noob and I am stuck with this particular error. I am trying to run a python script within my bash script. The error log looks like this
File "Alpha_Beta.py", line 6, in <module>
import pdb
File "C:\softs\Python\Lib\pdb.py", line 14, in <module>
File "C:\softs\Python\Lib\pprint.py", line 39, in <module>
ImportError: No module named cStringIO
This is on my ubuntu machine.
Can anyone please help me fix this bug?
By looking at the replies and the traceback I do figure out, it is probably something to do with the fact that the file was initially being used in Windows environment. Currently I am trying to compile this file on ubuntu. I hope this makes it more clear.
Also this file compiles without any problems when I run on the windows machine. Not the same with ubuntu. So I need help to figure out , how to debug this. Should I change something within the pdb module or should I look elsewhere.
You are running this on a Windows machine, but if this from a shared Ubuntu drive then the cStringIO extension will not import; it'll be compiled for running on Linux, not Windows.