I'm trying to package an app and include pymssql with it.
Here's my setup.py:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['AppName.py']
DATA_FILES = ['pic1.jpg', 'pic2.jpeg']
OPTIONS = {'argv_emulation': True,
'packages': ['tkinter', '_mssql', 'pymssql']
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
When I only include _mssql it gives this error:
error: cannot copy tree '/path_to_venv/lib/python3.4/site-packages/_mssql.so': not a directory
When I try with pymssql (or both) it gives this error:
Traceback (most recent call last):
File "setup.py", line 20, in <module>
setup_requires=['py2app'],
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/path_to_venv/lib/python3.4/site-packages/py2app/build_app.py", line 659, in run
self._run()
File "/path_to_venv/lib/python3.4/site-packages/py2app/build_app.py", line 865, in _run
self.run_normal()
File "/path_to_venv/lib/python3.4/site-packages/py2app/build_app.py", line 939, in run_normal
mf = self.get_modulefinder()
File "/path_to_venv/lib/python3.4/site-packages/py2app/build_app.py", line 814, in get_modulefinder
debug=debug,
File "/path_to_venv/lib/python3.4/site-packages/modulegraph/find_modules.py", line 341, in find_modules
find_needed_modules(mf, scripts, includes, packages)
File "/path_to_venv/lib/python3.4/site-packages/modulegraph/find_modules.py", line 266, in find_needed_modules
path = m.packagepath[0]
TypeError: 'NoneType' object is not subscriptable
Another note:
I can package the app fine without including either pymssql or _mssql in the setup file and when I try and run the app, here's the error I get in the OS Console:
1/12/16 10:00:48.618 AM AppName[72301]: Traceback (most recent call last):
1/12/16 10:00:48.618 AM AppName[72301]: File "/path_to_app/dist/AppName.app/Contents/Resources/__boot__.py", line 351, in <module>
1/12/16 10:00:48.618 AM AppName[72301]: _run()
1/12/16 10:00:48.619 AM AppName[72301]: File "/path_to_app/dist/AppName.app/Contents/Resources/__boot__.py", line 336, in _run
1/12/16 10:00:48.619 AM AppName[72301]: exec(compile(source, path, 'exec'), globals(), globals())
1/12/16 10:00:48.619 AM AppName[72301]: File "/path_to_app/dist/AppName.app/Contents/Resources/AppName.py", line 9, in <module>
1/12/16 10:00:48.619 AM AppName[72301]: import pymssql
1/12/16 10:00:48.619 AM AppName[72301]: File "_mssql.pxd", line 10, in init pymssql (pymssql.c:10984)
1/12/16 10:00:48.619 AM AppName[72301]: ImportError: No module named '_mssql'
I figured out a workaround. Probably not the best way, but it works now.
I added import _mssql into my main app script (already had import pymssql).
I then took my _mssql.pyx file and put a copy in my app dir.
I added _mssql.pyx under the DATA_FILES in the setup.py file.
You will need to include decimal and uuid into your setup.py file if not already included somewhere else.
Leave pymssql and _mssql out of the packages list in the setup.py file as py2app will find them and include them automatically.
You may need to include other libraries that the _mssql.pyx file will try and import. Just keep adding them until it works.
Related
I have already create an issue in github. But no one reply.
The question is:
I runpython3 setup.py py2app and the error:
Traceback (most recent call last):
File "/Users/th/source/duomai/send_email.py/setup.py", line 14, in <module>
setup(
File "/usr/local/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/usr/local/Cellar/python#3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/local/Cellar/python#3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/local/Cellar/python#3.9/3.9.0_5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/local/lib/python3.9/site-packages/py2app/build_app.py", line 925, in run
self._run()
File "/usr/local/lib/python3.9/site-packages/py2app/build_app.py", line 1147, in _run
self.run_normal()
File "/usr/local/lib/python3.9/site-packages/py2app/build_app.py", line 1244, in run_normal
self.process_recipes(mf, filters, flatpackages, loader_files)
File "/usr/local/lib/python3.9/site-packages/py2app/build_app.py", line 1099, in process_recipes
rval = check(self, mf)
File "/usr/local/lib/python3.9/site-packages/py2app/recipes/sip.py", line 111, in check
mf.import_hook("sip", m)
File "/usr/local/lib/python3.9/site-packages/modulegraph/modulegraph.py", line 1114, in import_hook
q, tail = self._find_head_package(parent, name, level)
File "/usr/local/lib/python3.9/site-packages/modulegraph/modulegraph.py", line 1215, in _find_head_package
raise ImportError("No module named " + qname)
ImportError: No module named sip
And my setup.py
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['cli.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
It's seems like qt relative. But I didn't used qt, I just use the tkinter...
The detail log is long, I create an attach. https://www.dropbox.com/s/4pcc9zv7dgoq37j/log.txt?dl=0
How to fix this?
Try adding the packages to your options in the setup file, like this:
OPTIONS = {
'argv_emulation': True,
'packages':['tkinter']}
I'm trying to compile python script to exe.
My script - hello.py:
print("hello")
My setup.py:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
name = 'hello',
description = 'hello script',
version = '1.0',
options = {'py2exe': {'bundle_files': 1, 'compressed': True,'dist_dir': ".",'dll_excludes':['w9xpopen.exe']}},
console = [{'script': r"hello.py"}],
zipfile = None,
)
I run:
py -3 setup.py install
The error:
py -3 setup.py install
running install
running build
running install_egg_info
Removing C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\hello-1.0-py3.7.egg-info
Writing C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\hello-1.0-py3.7.egg-info
running py2exe
Traceback (most recent call last):
File "setup.py", line 19, in <module>
zipfile = None,
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\runtime.py", line 160, in analyze
self.mf.import_hook(modname)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 357, in _find_and_load
self._scan_code(module.__code__, module)
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 388, in _scan_code
for what, args in self._scan_opcodes(code):
File "C:\Users\alonat\AppData\Local\Programs\Python\Python37-32\lib\site-packages\py2exe\mf3.py", line 417, in _scan_opcodes
yield "store", (names[oparg],)
IndexError: tuple index out of range
Do you know how to resolve this error?
py2exe seems to support up to Python 3.4 (thanks Michael Butscher)
However, there are other libraries such as Pyinstaller which work just fine, and are compatible with a variety of Python versions (from Python 2.7 to 3.5+)
Check it out, it's actually really easy :)
https://pyinstaller.readthedocs.io/en/stable/
I'm working on a Rally reporting tool for my team in Python, and I'm trying to package it using cx-freeze. I'm getting a ModuleNotFound error, and I'm wondering if it's because pygal isn't supported by cx-freeze (really hoping this isn't the case because I'd have to rewrite a lot of things)
celinaperalta$ /Users/celinaperalta/Documents/NYLTesting/rally-exports/build/exe.macosx-10.9-x86_64-3.7/RallyGUI ; exit;
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cx_Freeze/initscripts/__startup__.py", line 40, in run
module.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/cx_Freeze/initscripts/Console.py", line 37, in run
exec(code, {'__name__': '__main__'})
File "RallyGUI.py", line 8, in <module>
File "/Users/celinaperalta/Documents/NYLTesting/rally-exports/build/exe.macosx-10.9-x86_64-3.7/RallyReportTool.py", line 7, in <module>
import pygal
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pygal/__init__.py", line 28, in <module>
import pkg_resources
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 959, in <module>
class Environment:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 963, in Environment
self, search_path=None, platform=get_supported_platform(),
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 190, in get_supported_platform
plat = get_build_platform()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 395, in get_build_platform
plat = get_platform()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sysconfig.py", line 675, in get_platform
get_config_vars(),
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sysconfig.py", line 551, in get_config_vars
_init_posix(_CONFIG_VARS)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/sysconfig.py", line 422, in _init_posix
_temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
ModuleNotFoundError: No module named '_sysconfigdata_m_darwin_darwin'
cx_freeze does not include all the packages automatically. When you find ModuleNotFoundError, you need to inlcude the module explicitly in your setup like -
build_exe_options = {'packages': ['_sysconfigdata_m_darwin_darwin']}
I was giving a look at the "Learn Python The Hard Way" tutorial and when it told me to try it out by typing Python in Powershell after I installed it just kept giving me this:
PS C:\Users\Zach> python
Traceback (most recent call last):
File "C:\Python27\lib\site.py", line 548, in <module>
main()
File "C:\Python27\lib\site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "C:\Python27\lib\site.py", line 266, in addusersitepackages
user_site = getusersitepackages()
File "C:\Python27\lib\site.py", line 241, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "C:\Python27\lib\site.py", line 231, in getuserbase
USER_BASE = get_config_var('userbase')
File "C:\Python27\lib\sysconfig.py", line 516, in get_config_var
return get_config_vars().get(name)
File "C:\Python27\lib\sysconfig.py", line 449, in get_config_vars
import re
File "C:\Python27\lib\re.py", line 105, in <module>
import sre_compile
File "C:\Python27\lib\sre_compile.py", line 14, in <module>
import sre_parse
File "C:\Python27\lib\sre_parse.py", line 17, in <module>
from sre_constants import *
File "C:\Python27\lib\sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
I also tried running through the command prompt and got the same error. I've installed and uninstalled python about 3 times and have done a few reboots to no avail. I am very new to python and I'm confused on what to do here. I would also appreciate any links to other python tutorials.
In this case, from my understanding, you have no modules called "MAXREPEAT" or you(or the installer) have installed it somewhere wrong. A reinstallation or redirecting the path should get it to work.
When I attempt to do the following on a production server:
$ sudo -u vretnet ../bin/python setup.py test -q
It will show the following error, how should I fix this?
Or could it be that my development.ini went wrong?
Traceback (most recent call last):
File "setup.py", line 34, in <module>
paster_plugins=['pyramid'],
File "/opt/python3.2.3/lib/python3.2/distutils/core.py", line 148, in setup
dist.run_commands()
File "/opt/python3.2.3/lib/python3.2/distutils/dist.py", line 917, in run_commands
self.run_command(cmd)
File "/opt/python3.2.3/lib/python3.2/distutils/dist.py", line 936, in run_command
cmd_obj.run()
File "/home/vretnet/env/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/test.py", line 138, in run self.with_project_on_sys_path(self.run_tests)
File "/home/vretnet/env/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/test.py", line 118, in with_project_on_sys_path
func()
File "/home/vretnet/env/lib/python3.2/site-packages/distribute-0.6.34-py3.2.egg/setuptools/command/test.py", line 164, in run_tests
testLoader = cks
File "/opt/python3.2.3/lib/python3.2/unittest/main.py", line 123, in __init__
self.parseArgs(argv)
File "/opt/python3.2.3/lib/python3.2/unittest/main.py", line 191, in parseArgs
self.createTests()
File "/opt/python3.2.3/lib/python3.2/unittest/main.py", line 198, in createTests
self.module)
File "/opt/python3.2.3/lib/python3.2/unittest/loader.py", line 132, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/opt/python3.2.3/lib/python3.2/unittest/loader.py", line 132, in <listcomp>
suites = [self.loadTestsFromName(name, module) for name in names]
File "/opt/python3.2.3/lib/python3.2/unittest/loader.py", line 91, in loadTestsFromName
module = __import__('.'.join(parts_copy))
File "/home/vretnet/env/ECommerce/ecommerce/__init__.py", line 1, in <module>
from pyramid.config import Configurator
File "/home/vretnet/env/lib/python3.2/site-packages/pyramid-1.4-py3.2.egg/pyramid/config/__init__.py", line 10, in <module>
from webob.exc import WSGIHTTPException as WebobWSGIHTTPException
File "/home/vretnet/env/lib/python3.2/site-packages/WebOb-1.2.3-py3.2.egg/webob/exc.py", line 1115, in <module>
from paste import httpexceptions
File "/home/vretnet/env/lib/python3.2/site-packages/Paste-1.7.5.1-py3.2.egg/paste/httpexceptions.py", line 634
except HTTPException, exc:
^
SyntaxError: invalid syntax
It is Python 3, you should write as:
except HTTPException as exc:
This took me a couple of days to figure out ><. But make sure you install the correct mod_wsgi version. You can install that uses python2 or one that uses python3.
If you install the python3 wsgi mod and use virtualenv2 to build your python environment you will get packages that aren't written for python3.
you just use this patch bellow.
$ 2to3 example.py
https://docs.python.org/2.7/library/2to3.html#to3-python-2-3
translate code from python2 to python3 automatically and recursively.