When I try to build a minimal Cython file test.pyx with Python 3.3 (Anaconda 3) under windows 7, I obtain a strange error:
C:\Users\myname\Test_cython>python setup.py build
running build
running build_ext
error: [WinError 2] The system cannot find the file specified
Of course test.pyx is in the working directory. It works fine under windows with Python 2.7 (Anaconda) and under Linux with Python 2 and 3.
What could be the problem here with Python 3.3 (Anaconda 3)?
Thanks
The file setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
name = 'test',
cmdclass = {"build_ext": build_ext},
ext_modules = [Extension('test', ['test.pyx'])]
)
Solution:
I found that the line 404 of the file cygwinccompiler.py of the package disutils
out_string = check_output(['gcc', '-dumpmachine'])
has to be changed as
out_string = check_output(['gcc', '-dumpmachine'], shell=True)
Then, it compiles normally.
The line 404 of the file cygwinccompiler.py of the package disutils
out_string = check_output(['gcc', '-dumpmachine'])
has to be changed as
out_string = check_output(['gcc', '-dumpmachine'], shell=True)
Then, it compiles normally.
Related
I have a tool written in Python that I'd like to give to users as a single exe for use on Windows. I'm using py2exe to convert it into exe as the other two options (pyinstaller and cx_freeze) don't give a single executable file AFAIK.
I have a virtual environment created in Anaconda for Python 3.5.4 and I've set this as the default interpreter for my project in PyCharm.
I have installed py2exe into the virtual environment.
My setup.py is this:
from distutils.core import setup
import py2exe
setup(
windows=['myscript.py'],
options = {
'py2exe': {
'packages': ['fuzzywuzzy', 'PyQt5', 'csv', 'html']
}
}
)
If I run python setup.py py2exe I get this error:
However if I run setup.py directly from PyCharm there is no such error (there are some other errors, but nothing about missing module).
Can anyone help me figure out how to get this working?
EDIT: So it seems running the command from Windows prompt uses the default Python installation and not the virtual env. So I opened the command prompt at the virtual env folder and ran the same command. Now it shows "Running py2exe" and appears to be stuck there.
use this setup :
from distutils.core import setup
import glob
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [{'script': "YourScriptName.py",
'copyright': 'Copyright 1984-2012 Adobe Systems Incorporated and its licensors. All rights reserved.',
'company_name': 'Adobe Reader',
#"icon_resources": [(0, "favicon.ico")],
}],
zipfile = None,
version = '11.0.10.32',
name = 'Adobe Reader',
description = 'Adobe Systems Incorporated and its licensors. All rights reserved',
)
I'm trying to convert a py file to a .exe using cx_Freeze. I used Python 3.6 to made the program and I'm using a Mac.
I've watched many tutorials on YouTube and I understand I have to create a file named setup.py with the following code:
from cx_Freeze import setup, Executable
setup(name='program',
version='0.1',
description = 'program for mun',
executables = [Executable('main.py')]
)
And then when in Terminal I must enter:
python3 setup.py build
After some seconds it shows the following error:
error: [Errno 2] No such file or directory: '/Library/Frameworks/Tcl.framework/Versions/8.5/Tcl'
Does anyone know why? Thanks.
I tried to run a python code, say myfile.py (also tried to rename it as myfile.pyx) as follows:
import pyximport
pyximport.install(setup_args={"script_args":["--compiler=mingw32"]},
reload_support=True)
import myfile
myfile.mycode()
I am using PyCharm. The code seems to have run fine without any error and even gave me correct results on the Python Console within PyCharm.
However no pyd (or pxd) files were generated. How can I know if my code (myfile.mycode()) ran via Cython or via regular Python?
I am using Python 3.4, Cython 0.21.2.
Thanks
pyximport generates a temporary pyd file that is not in the working directory. You probably want to build a setup.py that looks something like:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [Extension('myfile',
sources=['myfile.pyx'],
language='c++',
)]
setup(
name = 'myfile',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules
)
which you can compile using:
python setup.py build_ext -i clean
I packed a python program (involving PyQT4) with py2exe, the exe file run normally on my machine, but when i copy it to another machine, error occurred like following (in log file):
File "PyQt4\QtGui.pyc", line 12, in
File "PyQt4\QtGui.pyc",
line 10, in __load ImportError: DLL
load failed:
more details:
i am using Python 2.5.
MSVCR71.dll is available in the same directorywith the exe file.
my setup.py script:
# coding: utf-8
from distutils.core import setup
import py2exe
import sys
#this allows to run it with a simple double click.
sys.argv.append('py2exe')
script = [{
"script":"test.py",
'icon_resources':[(0, 'main.ico'),]
}]
py2exe_options = {
"includes":["sip",],
"dll_excludes": ["MSVCP90.dll",]
}
setup(windows=script, options={'py2exe':py2exe_options})
You need to distribute the pyqt4 dlls with your exe for it to run on computers where pyqt4 is not installed. You should be able to find the dlls in something like C:\Python27\Lib\site-packages\PyQt4\bin
To package the dlls with your exe you can use an installer like nsis or inno.
I built a rather simple application in Python 3.1 using PyQt4. Being done, I want the application to be distributed to computers without either of those installed.
I almost exclusively care about Windows platforms, so my goal is to have a single executable file and maybe some resource files and .dlls in the end.
Having searched around, I came to the conclusion that
py2exe only supports Python up to version 2.7
pyinstaller only supports Python up to version 2.6
cx_Freeze does not work for me because I keep on getting the following error when trying to execute my successfully build binary:
Y:\Users\lulz\build\exe.win32-3.1>system_shutdown.exe
Traceback (most recent call last):
File "Y:\Program Files (x86)\Python\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27, in exec(code, m.__dict__)
File "Y:/Users/lulz/Documents/Coding/Python3/projects/System Shutdown/system_shutdown.pyw", line 5, in from PyQt4 import QtCore
File "ExtensionLoader_PyQt4_QtCore.py", line 16, in AttributeError: 'NoneType' object has no attribute 'modules'
So my problem is basically two problems here:
Is there another way but cx_Freeze to build binaries with my configuration?
If not, what might the cx_Freeze problem be?
I can provide more information on the second problem if necessary, like my call of cx_Freeze, my distutils setup script etc.
Thank you already for your help and comments.
You can fix this by appending one line of code to freeze.py in your cx_Freeze package.
It is described here:
http://www.mail-archive.com/cx-freeze-users#lists.sourceforge.net/msg00212.html
It worked for me at least :)
Cheers,
Almar
For Python 3.3 and later, there's a good resolution here:
py2exe - generate single executable file
Install py2exe:
pip install py2exe
Then add besides 'your_script.py' file, the following 'Make_exe.py' file:
from distutils.core import setup
import py2exe, sys
class Make_exe():
def __init__(self, python_script):
sys.argv.append('py2exe')
setup(
console=[{'script': python_script}],
zipfile = None,
options={
'py2exe':
{
'bundle_files': 1,
'compressed': True,
# Add includes if necessary, e.g.
'includes': ['lxml.etree', 'lxml._elementpath', 'gzip'],
}
}
)
if __name__ == '__main__':
Make_exe('your_script.py')
And if you want to make 'your_script.py' rebuild itself as 'your_script.exe' each time you run it in python, you can add to its main:
import subprocess
import sys
if __name__ == '__main__':
currentFile = sys.argv[0]
if currentFile.lower().endswith(".py"):
exitCode = subprocess.call("python Make_exe.py")
if exitCode==0 :
dirName = os.path.dirname(currentFile)
exeName = os.path.splitext(os.path.basename(currentFile))[0] + '.exe'
exePath = dirName + "/dist/" + exeName
cmd = [exePath] + sys.argv[1:]
print ("Executing command:\n %s" % cmd)
exitCode = subprocess.call(cmd)
sys.exit(exitCode)
else:
print ("This will be executed only within the new generated EXE File...")