My python script includes a Qt GUI which I'm trying to convert into a Windows executable using Py2exe. My script is using the Tweepy module to fetch data from Twitter. So I include Tweepy and try to compile it into an executable using the following Setup.py:
from distutils.core import setup
import py2exe
setup(
windows = [{"script": "main.py"}],
options = {"py2exe":{"includes":["sip", "tweepy"]}}
)
The following Error gets raised:
raise ImportError, "No module named " + qname
ImportError: No module named tweepy
I've succesfully used the same setup file (minus the 'Tweepy include') to compile other script in the past. What am I missing here?
Assuming that you have tweepy installed in the python installation that you are trying to build with try adding:
import tweepy
near the start of your setup.py to ensure that py2exe can really see it, some packages do some interesting things during import.
Related
I tried using pyinstaller to get my .py file into an exe, but I cannot get the geemap package to bundle with it.
I am now trying to use py2exe, and I can see geemap is included in the library.zip file.
However, I get the following error when running the exe, and have tried importing http2lib already...
ImportError: cannot import name 'socks' from 'httplib2 (C:\...\library.zip\httplib2\__init__.pyc)'
I have a Cython module compiled from pyx files to c files that I am trying to import and use in a python module. I'm running python 3.6 on a Mac. When I run gcc -v the output is:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr - -with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.1 (clang-1001.0.46.4) Target: x86_64-apple-darwin18.7.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Running python setup.py build and python setup.py install gives no errors, and the .so and .c files for the corresponding files appear in the right directory, which is on the path.
When I try to import the module, I get an error in the init file, from a line that tries to import another submodule:
from . import subModule
I've tried updating python and Cython, and I've made sure that gcc is in user/lib.
This is my setup.py file:
from Cython.Build import cythonize
setupArgs = dict(
name="module",
version="1.1.0",
description=description,
url="https://github.com/XXXX/XXXXX/module",
author="CTcue",
author_email="info#XXXXXX.com",
ext_modules=cythonize(["module/*.pyx"]),
)
# Use distutils setup
from distutils.core import setup
setup(**setupArgs)
This is the error message:
File "module/subModule.pyx", line 4, in init module.subModule
ModuleNotFoundError: No module named 'thirdModule'
The thirdModule in question has a .c file and a .so file that correspond to the .pyx file, and as far as I can tell everything is order there.
module's init.py:
__title__ = 'Pseudonomizer'
__version__ = '1.0.2'
__author__ = 'CTcue'
__license__ = 'Proprietary'
__copyright__ = 'Copyright 2016 CTcue'
from . import subModule
subModule:
import thirdModule
thirdModule.doSomething()
third module:
import re
from . import anotherModule
def doSomething:
#code that does something
Edit : In an attempt to see if the compiler is at fault, I tried to manually compile the .c file of thirdModule with "gcc thirdModule", and got the following error:
Undefined symbols for architecture x86_64:
This seems to suggest that the issue is compiler-related, but I still haven't found the solution.
Any help would be much appreciated.
It turns out #ead was right, and the problem was that the module had implicit relative imports which are no longer allowed in python 3.
I have created the following Python script using the gspread and oauth2 modules
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
credentials = SignedJwtAssertionCredentials("client_email","private_key", "https://spreadsheets.google.com/feeds")
gc = gspread.authorize(credentials)
spreadsheet = gc.open_by_key("spreadsheet_id")
worksheet = spreadsheet.worksheet("sheet_name")
lstoforders = worksheet.get_all_values()
...some extra code...
When I run this code as a .py file everything works smoothly. However, when I try to package it into an executable Windows program using py2exe, I get the following output
The following modules appear to be missing
['ElementC14N', 'IronPythonConsole', 'System', 'System.Windows.Forms.Clipboard', '_scproxy', 'ca_certs_locater', 'clr', 'console', 'email.FeedParser', 'email.Message', 'email.Utils', 'google.appengine.api', 'google.appengine.api.urlfetch','google3.apphosting.api', 'google3.apphosting.api.urlfetch', 'http', 'modes.editingmodes', 'oauth2client.client' 'pyreadline.keysyms.make_KeyPress', 'pyreadline.keysyms.make_KeyPress_from_keydescr', 'pyreadline.keysyms.make_keyinfo', 'pyreadline.keysyms.make_keysym', 'startup', 'urllib.parse']
Accordingly, when I try to run the resulting exe file, I get the following error
Traceback (most recent call last):
File "gspread_to_autocomplete_json.py", line 2, in <module> ImportError: No module named oauth2client.client
It appears as if py2exe cannot find the gspread and oauth2client.client modules. These modules are installed on my machine.
Does anybody have a clue why this is happening?
Thanks.
Nicola
You can choose in your setup.py with packages and modules you want to include.It might be that your setup script is not finding all the dependencies automatically (actually it is pretty common).Try to have a look at the answer I gave to this question.
Add options to your setup.py
You can also use more py2exe options in order that you are importing all the modules and the packages required by your project. E.g.
# setup.py
from distutils.core import setup
import py2exe
setup(console=["script.py"],
options={
"py2exe":{
"optimize": 2,
"includes": ["mf1.py", "mf2.py", "mf3.py"], # List of all the modules you want to import
"packages": ["package1"] # List of the package you want to make sure that will be imported
}
}
)
In this way you can force the import of the missing script of your project
I am trying to run this python rewrite of Vlfeat library.
https://github.com/shackenberg/phow_caltech101.py. I am trying to run the application phow_caltech101.
This is throwing
File "/A/B/C/pyvlfeat-0.1.1a3/vlfeat/__init__.py", line 1, in <module>
import _vlfeat
ImportError: No module named _vlfeat
In the corresponding "init.py" file, I can see it is mentioned as "import _vlfeat". I am new to python, please let me know what is causing this error?
You need to download and install PyVlfeat module.
https://pypi.python.org/pypi/pyvlfeat/
As I see, pyvlfeat has some dependencies, so be sure to download these too:
Boost.Python (tested against version 1.35.0-5)
NumPy (tested against version 1.5.1)
Matplotlib (tested against version 0.99.3)
So I am trying to freeze a Python script as an .exe. I installed cx_freeze to do so as I am using 3.4. I created the setup.py file successfully and also ran the build which appears in the build folder and .exe appears. However, when I open the .exe it displays the following error:
zipimport.ZipImportError: can't find module 'cx_Freeze__init__'
Fatal python error: unable to locate initialization module
Current thread 0x00001d58 <most recent call first>:
I believe I did everything else correctly. There is indeed a cx_Freeze_init_.pyc file in the library.zip, however it cannot find it for some reason. The only other error I had was that certain modules were missing when during the cmd build:
Missing modules:
? _dummy_threading imported from dummy_threading
? ce imported from os
? doctest imported from heapq
? getopt imported from base64, quopri
? org.python.core imported from copy
? os.path imported from os
? posix imported from os
? pwd imported from posixpath
? subprocess imported from os
This is not necessarily a problem - the modules may not be needed on this platfo
rm.
This is the setup.py I used:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
base = 'Console'
executables = [
Executable('guess.py', base=base)
]
setup(name='Guess',
version = '1.0',
description = 'test',
options = dict(build_exe = buildOptions),
executables = executables)
Thanks in advance!