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.
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.
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
Pyinstaller recently stopped importing a module that it previously had no problem with so I set up a simple test case to isolate the problem.
I created a script (pt.py) as follows:
import py_script1
import py_script
print('hello world')
py_script.py and py_script1.py are identical and located in the same directory as pt.py. They both import os, random and math and have some functions in them.
When running pyinstaller with default settings it compiles the .exe file but when I try to run it, I get "ImportError: No module named py_script". Checking the warnings text file shows that it was never compiled into the .exe file.
Changing the order of the imports doesn't help - I get the same error. I have also tried to uninstall and reinstall pyinstaller but that has not helped
How is this even possible - the two imported scripts are identical and are located in the same place!
More importantly how do I fix this problem?
PyInstaller 3.3.1
Python 3.3.5
Windows 10
I solved it. Despite the misleading exception description I isolated the problem as the following line in the imported file:
SB_CONSTANT = 0.00000005670373 #Stefan–Boltzmann constant (W/m2/K4)
For some reason this number broke pyinstaller. I changed it to:
SB_CONSTANT = 5.6704e-8
...and the module imported fine.
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.
Brand new to Python, coming from Ruby.
I have a script that works perfectly if I run it form ipython or ipython qtconsole. I then tried to turn it into an executable script -- threw #!/usr/bin/env python at the top.
Running the script throws an error:
$ ./script/myscript.py
Traceback (most recent call last):
File "./script/myscript.py", line 6, in <module>
import yaml
ImportError: No module named yaml
Obviously there's something wrong with how python is loading modules (as it works perfectly fine from the REPL) but I have no idea how to fix it.
Thanks!
What is likely happening is you have more than one version of Python installed on your system, and the yaml module is only installed in one of them. When you run ipython it's using one version, but your script's shebang line is finding another version. Run
head `which ipython`
and see if it matches up to the result of which python (I'm betting it won't). Once you know the path to the python binary being used by ipython, you can specifically define it in your script's shebang line.
As a long-term fix, edit your $PATH variable and put the directory containing your desired version of Python ahead of the directory shown by which python, so that you can continue to use #!/usr/bin/env python as a shebang.
ipython must be pointing at a different version of python than what is in PYTHONPATH.
You can find out by looking at cat /usr/local/bin/ipython.
Look at
ipython reads wrong python version