I am trying to build a Python extension with Cython.
My OS is Windows7 64-bit, with Python2.7.5 32-bit, Cython 0.19.1, and Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1.
I tried to follow the instruction at this page to build a "Hello World" example.
I've wrote the "Hello World" Python script and "setup" file (actuall copy and paste) as the instruction told, and rename them properly.
Then I ran the setup.py as instructed:
python setup.py build_ext --inplace
There are no errors or warnings in the output. However, I cannot find the helloworld.dll in the folder.
Where was I wrong??
According to #martineau 's advice, I used sys.path.appendsys.path.append('<path_to_pyd_directory>') before I import my extension, and it works well.
The code I used is as follows:
import sys
sys.path.append("C:\Python27\Practice")
import helloworld
The output I have is:
Hello World
Many thanks to #martun again! :-)
Related
It looks like py2exe is looking for the file "run-py3
.4-win32.exe'", the folder mentioned in the error exists, but it looks like no file is there. This is a simple "Helloworld.py" application, just learning how to build exe's. I installed the source ( https://pypi.python.org/pypi/py2exe/0.9.2.2 ) and it looked like it built fine.
Any ideas of where to start?
...\buildtry1> py -3.4 setup.py py2exe
running py2exe
1 missing Modules
? readline imported from cmd, code, pdb
Building 'dist\helloworld.exe'.
error: [Errno 2] No such file or directory: 'C:\\Python34\\lib\\site- packages\\py2exe-0.9.2.2-py3.4.egg\\py2exe\\run-py3.4-win32.exe'
setup.py and helloworld.py are in the same directory
Update
Turned off virus scan and reinstalled PY2EXE, all is well.
I disabled virus scan, deleted my py2exe folder in python34 directory. Reinstalled py2exe and it ran without error.
There is a blank space in your path directory. Just after "sites- ", check if this is your problem.
Try this:
Update py2exe. If that doesn't work:
Install python 3.3 or any other python 3 version suitable for py2exe. run it with py -3.3 setup.py py2exe
I have been using python 3.3
This is an old problem as I searched, and this is what I did:
helloworld.pyx
print("Hello world!")
Then, in ipython, I did:
import pyximport; pyximport.install()
import helloworld
It says:
ImportError: Building module helloworld failed: ["ValueError:
['path']\n"]
The same problem did not happen with python 2.7
I googled this: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
and realized that I have to install Windows SDK for Windows 7 and .NET Framework 4. As it comes with the VC++2010 Redistributables, I did not install the redistributables alone again. I thought I had everything ready, but the import error still remains.
Could anyone please help me solve it?
Thank you!
-Shawn
install Windows 7 SDK, then open cmd run:
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.Cmd" /Release /x64
then run:
python setup.py install
I was having the same issue and the same environment (win7 64bit, python-3.3.3 64bit).
I have
installed the Windows 7 SDK as described on the wiki cython wiki as you did,
applied the patch (msvccompiler9_33.diff) from this python bug,
fixed the above patch by defining a missing variable as described here
Installed MS Visual C++ Express 2010 (seems to be required)
Updated the Windows 7 SDK to include the "Windows Headers and Libraries", "Tools" and of course the "Visual C++ Compilers" the MSVC++2010 redistributable.
And now I can compile and import the helloworld.py just fine.
I have installed Portable Python 3.2.1.1 on windows 8 and i also have installed pypdf2
using setup.py install command on cmd.
but when I try to import the module it is giving me an error
"import error: no module named pypdf2"
is installation on portable python different?
All efforts to make this work with PortablePython 3.2.5.1 failed. But this is the Portable Python 2.7.5.1 version of it. I did it on Windows 7! Screenshot
I downloaded PyPDF2 from https://github.com/mstamy2/PyPDF2 and extracted the folder.
I found the folder PyPDF2-master and went into it to reveal PyPDF2.
I copied the folder PyPDF2 into the path "Python 2.7.5.1\App\Lib"
I went back to Portable "Python 2.7.5.1\App" and started python.exe
I've also attached a screenshot. I hope this will also work for you.
How can I convert my python program with Qt for GUI to .exe file??
I want to make an installation file for my python source code
First part : "How can I convert my python program with Qt for GUI to .exe file??"
You can use PyInstaller, which supports python 2.2 - 2.7 and it has a hook system for including Qt with all dlls and plugins.
You can use also :
bbfreeze
cxfreeze
py2exe (pretty old)
esky (a wrapper of all the above except PyInstaller)
Basically all this systems have a definition file to handle and produce the binary package. For instance, esky has a setup.py (which is a distutil file) to produce the package :
from esky import bdist_esky
from distutils.core import setup
setup(name="appname",
version="1.2.3",
scripts=["appname/script1.py","appname/gui/script2.pyw"],
options={"bdist_esky":{"includes":["mylib"]}},
)
Than you can call "python setup.py bdist_esky"
For PyInstaller the thing is pretty different. From console, cd in PyInstaller folder :
python Makespec.py [options] script.py
This produce a spec file with all the options to package your script. You can also modify this file with an editor.
python Build.py script.spec
This analyzes and builds your exe (or os binary equivalent).
Second part : "I want to make an installation file for my python source code"
You have to use NSIS, InnoSetup, BitRock Installer, IzPack or equivalent to produce a platform installer. So you have to take the binary result produced on the first part and package it for os distribution. Almost all the installer systems are thought for Windows systems.
Cross platform : Zero Install, IzPack ...
If you use IzPack you can have a cross platform installer paying the price of including a jvm.
Using Py2Exe is the most suitable choice here.
PY2EXE Binaries :http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/
Usage :
Create a new setup python file:
from distutils.core import setup
import py2exe
setup(console=['Your python script absolute path'])
Save this file.
Goto Command Prompt and change directory where the setup.py file is saved.
Run the command :
[python <your python script name_to be converted in exe> py2exe]
I cannot post the images as I don't have 10 reputations to post more than two links. Please comment if any help required.
I am following the tutorial for py2exe from this site http://www.py2exe.org/index.cgi/Tutorial
this is the setup code:
from distutils.core import setup
import py2exe
setup(console=['script.py'])
when I type in cmd:
python setup.py install
I get this:
running install
running build
my script works fine and I even tried it for simple scripts such as
print "hello world"
I was able to use py2exe before without any problems but for some reason it stop working for me. I even tried to reinstall the module but it still won't do anything. Any idea's from those brilliant minds on stack overflow?
To build an exe, the command is:
python setup.py py2exe