If I run:
ti.py (only part of code)
import pygtk
import gtk
I get:
File ti.py.line 2 , in (module)
import gtk
File"C:\python27\lib\site-packages/gtk-2.0\gtk\__init__.py",line 40 in (module)
from gtk import _gtk
ImporError : DLL Load Failed: The specified procedure could not be found.
But if I run it inside shell it works perfectly.
The Python script gives the ImportError, whilst in the shell it imported perfectly.
I have installed pygtk 2.24 from the all in one installer.
What is the cause?
Related
My python app runs fine when I run it through my IDE (Pycharm), without any problems.
But as soon as I create an executable (via the command line:
"pyinstaller --onefile -w main.py"), and then I launch the executable, I get this message:
I have installed PIL via the Pillow module, because PIL directly did not work.
My script starts with all the dependencies:
from PIL import Image as Img,ImageTk
import imageio
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
import os
All the python scripts and folders and environment are set within the project root folder.
Why is this happening and what can I do to create an executable that actually works?
I installed python 3.8.8 and installed wxpython using pip at terminal
pip install wxpython
and i run simple program
import wx
print(wx.version())
in pycharm and pycharm`s python console, I got
ModuleNotFoundError: No module named 'wx'
in IDLE, I got
Traceback (most recent call last):
File "C:/Users/tasoo/OneDrive/Desktop/wx.py", line 1, in <module>
import wx
File "C:/Users/tasoo/OneDrive/Desktop\wx.py", line 2, in <module>
print(wx.version())
AttributeError: partially initialized module 'wx' has no attribute 'version' (most likely due to a circular import)
in python.exe code works
I want to import wx in pycharm project.
I tried add python in system path but it didn`t work.
You have problem because you saved code in file wx.py and now import wx loads your file wx.py instead of module wx. Rename your file - ie. main.py instead of wx.py
PyCharm may have own Python installed and it may need to install wx in this Python.
Check
import sys
print(sys.executable)
to get full path to Python used by PyCharm and then use this path
/full/path/to/python -m pip install wx
Or search in PyCharm settings (in menu File) and change Python Interpreter.
In PyCharm for every project you may set different Python - if you have installed many versions.
Importing a python site-package (e.g. 'scipy') works fine from a script test.py, but not from tkinter button command. When click the button, error shows:
ModuleNotFoundError: No module named 'scipy'
test.py
import scipy
print ("hello world")
GUI.py
import sys
import os
import tkinter
top=tkinter.Tk()
def startCamera():
os.system('python test.py')
B=tkinter.Button(top,text="hello",command= startCamera)
B.pack()
top.mainloop()
Both the test.py and GUI.py are in a same folder:
C:\Users\Breda\PycharmProjects\face_reg\face
scipy package in: C:\Users\Breda\Anaconda3\Lib\site-packages
sys.path variable contains: C:\Users\Breda\Anaconda3\Lib\site-packages
I tried to import other site-packages in test.py and run via GUI button command , all face the same problem. Any ideas?
The reason why the scipy module could not be found is because the python executable run by os.system was not part of the python installation which had scipy installed. (There is more than one python distribution installed on this machine.)
The issue was diagnosed by putting
import sys
print(sys.executable)
at the top of the test.py file (before import scipy). This prints the path to the python executable. Then test.py was run twice -- once from the command-line, and once through GUI.py. The two test runs printed different paths.
The problem was fixed by setting Pycharm's default python executable to the Anaconda Python3 installation which has the scipy module installed.
I want to do an executable, but ervery time I run the .exe it writes ImportError: No module named 'tkinter', and all I read on Stackowerflow do not help me !
My python program is simple (ODE solver) and requests only :
from math import*
from pylab import*
import numpy as np
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
I paste a copy of my prog.py into the C:\Python\Scripts folder where pyInstaller is. I compute the command line pyinstaller -F eulersolver.py, this creates a prog.exe in the dist folder. When I run this code I have
ImportError: No module named 'tkinter'
Failed to execute script prog
But my program do not use this module... do you have any proposition or help for me ?
OS : Windows64
Python : 3.5 for Win64
Note : I already unistall/install python 3 times today (after reading documentation on this webside and abroad).
Note 2 : I use Python only for scientific issues. I am no computer scientist, so be kind to me when explaining computer stuff :S
FINALLY WORKED FOR pyinstaller -F --hidden-import=tkinter --hidden-import=tkinter.filedialog prog.py Thanks a lot !!!
You should use hidden import
pyinstaller eulersolver.py --hidden-import=tkinter -y
The problem is that pyinstaller won't see second level imports. So if you import module A, pyinstaller sees this. But any additional module that is imported in A will not be seen.
There is no need to change anything in your python scripts. You can directly add the missing imports to the spec file (prog.spec in your case).
Just change the following line:
hiddenimports=[],
to
hiddenimports=["tkinter"],
After that run pyinstaller prog.spec to create the prog.exe.
I am trying to set up IBPY and Python on my Mac to run with Interactive Brokers. I have installed Git. I created a subdirectory ibapi under Home. I downloaded IBPy using git clone https://github.com/blampe/IbPy from the ibapi directory.
I am now trying to run the Demo.py program in Spyder. When I choose Run, I receive the error message:
ImportError: No module named Ib.Message
The first few lines of the demo program are:
import os
import sys
import time
import Ib.Message
import Ib.Socket
import Ib.Type
I am also trying to run a sample program: ib_api_demo from http://www.quantstart.com/articles/Using-Python-IBPy-and-the-Interactive-Brokers-API-to-Automate-Trades. When I try to run this, I get the error message:
ImportError: No module named ib.ext.Contract
The first few lines are:
from ib.ext.Contract import Contract
from ib.ext.Order import Order
from ib.opt import Connection, message
I figured this out. The problem was I was launching Spyder from my Mac Finder. When I did this, I received the error messages. When I launched Spyder (actually Anaconda Python) by typing "Spyder" in the Terminal window, this launched Anaconda Python. From here, I could run all my programs successfully with no errors.