Error running executable compiled with py2exe - python

I'm trying use py2exe to compile an eye tracking experiment written in Python 2.7 (32-bit). The experiment uses the psychopy library. I wrote the experiment using the PyCharm IDE, and the experiment runs when I run it through the PyCharm IDE, using an interpreter in a virtual environment located at C:\Users\phil\Python_2.7_32-bit.
The experiment compiles without generating any errors when I enter the following command into the command prompt: C:\Users\phil\Python_2.7_32-bit\Scripts\python.exe C:\Users\phil\PycharmProjects\iTRAC\VisSearch\setup.py py2exe.
When I run the executable generated by the above py2exe command, I get this error:
Traceback (most recent call last):
File "VisualSearch.py", line 3, in <module>
File "psychopy\__init__.pyc", line 39, in <module>
File "psychopy\preferences\__init__.pyc", line 5, in <module>
File "psychopy\preferences\preferences.pyc", line 172, in <module>
File "psychopy\preferences\preferences.pyc", line 33, in __init__
File "psychopy\preferences\preferences.pyc", line 98, in loadAll
File "psychopy\preferences\preferences.pyc", line 146, in loadAppData
File "psychopy\preferences\configobj.pyc", line 583, in __getitem__
KeyError: 'builder'
My setup.py script is as follows:
from distutils.core import setup
import py2exe
setup(windows =['C:\Users\phil\PycharmProjects\iTRAC\VisSearch\VisualSearch.py'])
I've also tried using the following setup.py script with the same results:
from distutils.core import setup
import py2exe
setup(windows = [{'script':'C:\Users\phil\PycharmProjects\iTRAC\VisSearch\VisualSearch.py',
'options' : {'py2exe':{'includes':['psychopy'],
'compressed': True,
'bundle_files': 1,}}}])
I googled the error and came up with 0 results.
Can anybody tell me why I am running into this error?

This is probably a missing config/prefs file. PsychoPy uses the configobj library to read and validate preferences but my guess is that py2exe is only automatically packaging py/pyc files and needs to include the .spec files in the psychopy/preferences folder.

Related

Scrapy not recognised command

I have successfully installed Scrapy and all it's dependencies into Python.org 64 shell on a Windows Vista 64 bit platform. This is installed as Site Package. I have tested Scrapy works ok at a basic level by typing:
Import Scrapy
Into a Python Shell and got no errors. I've just got started with tutorials on how to use Scrapy. Most of these suggest setting up a new project using the following Command Prompt line:
C:\Python27>scrapy startproject myproject
However this throws up the error message in the title about Scrapy being an invalid command. I have tried amending my environment variables to allow me to use this command from any file location within Command Prompt. I have added the following to the end of my environment variables:
C:\Python27;C:\Python27\Scripts;C:\Python27\Lib\site-packages\scrapy;C:\Python27\Scrapy
This does not seem to resolve the problem however as I still get the same error message. I have also tried running the 'scrapy startproject myproject' command from the following locations with Command Prompt:
C:\Python27
C:\Python27\Scripts
C:\Python27\Scrapy
This again still throws up the same error message. I feel like I am quite close to having the solution, but I just cant quite seem to make it work.
Can anyone spot where I am going wrong?
Thanks
EDIT:
In response to the last comment above from MattDMo, the command now works, however it now throws up the following error message, which I'm not even sure where to start with:
C:\Python27\Scripts>scrapy startprogram mrscript
Traceback (most recent call last):
File "c:\Python27\Scripts\scrapy", line 3, in <module>
from scrapy.cmdline import execute
File "c:\Python27\lib\site-packages\scrapy\cmdline.py", line 9, in <module>
from scrapy.crawler import CrawlerProcess
File "c:\Python27\lib\site-packages\scrapy\crawler.py", line 3, in <module>
from twisted.internet import reactor, defer
File "c:\Python27\lib\site-packages\twisted\internet\reactor.py", line 38, in
<module>
from twisted.internet import default
File "c:\Python27\lib\site-packages\twisted\internet\default.py", line 56, in
<module>
install = _getInstallFunction(platform)
File "c:\Python27\lib\site-packages\twisted\internet\default.py", line 50, in
_getInstallFunction
from twisted.internet.selectreactor import install
File "c:\Python27\lib\site-packages\twisted\internet\selectreactor.py", line 1
8, in <module>
from twisted.internet import posixbase
File "c:\Python27\lib\site-packages\twisted\internet\posixbase.py", line 24, i
n <module>
from twisted.internet import error, udp, tcp
File "c:\Python27\lib\site-packages\twisted\internet\tcp.py", line 29, in <mod
ule>
from twisted.internet._newtls import (
File "c:\Python27\lib\site-packages\twisted\internet\_newtls.py", line 21, in
<module>
from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol
File "c:\Python27\lib\site-packages\twisted\protocols\tls.py", line 41, in <mo
dule>
from OpenSSL.SSL import Error, ZeroReturnError, WantReadError
File "c:\Python27\lib\site-packages\OpenSSL\__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "c:\Python27\lib\site-packages\OpenSSL\rand.py", line 11, in <module>
from OpenSSL._util import (
File "c:\Python27\lib\site-packages\OpenSSL\_util.py", line 4, in <module>
binding = Binding()
File "c:\Python27\lib\site-packages\cryptography\hazmat\bindings\openssl\bindi
ng.py", line 87, in __init__
self._ensure_ffi_initialized()
File "c:\Python27\lib\site-packages\cryptography\hazmat\bindings\openssl\bindi
ng.py", line 106, in _ensure_ffi_initialized
libraries=libraries,
File "c:\Python27\lib\site-packages\cryptography\hazmat\bindings\utils.py", li
ne 80, in build_ffi
extra_link_args=extra_link_args,
File "c:\Python27\lib\site-packages\cffi\api.py", line 341, in verify
lib = self.verifier.load_library()
File "c:\Python27\lib\site-packages\cffi\verifier.py", line 75, in load_librar
y
return self._load_library()
File "c:\Python27\lib\site-packages\cffi\verifier.py", line 151, in _load_libr
ary
return self._vengine.load_library()
File "c:\Python27\lib\site-packages\cffi\vengine_cpy.py", line 138, in load_li
brary
raise ffiplatform.VerificationError(error)
cffi.ffiplatform.VerificationError: importing 'c:\\Python27\\lib\\site-packages\
\cryptography\\_Cryptography_cffi_444d7397xa22f8491.pyd': DLL load failed: The s
pecified module could not be found.
Is this actually an error log or just a standard print out? Also, could someone explain please why adding a .bat file to my Python scripts causes this to work?
Thanks
pip install scrapy installs a file called scrapy in Python's Scripts directory on Windows, the default location for which is C:\Python27\Scripts. However, C:\Python27\Scripts\scrapy is a Python file, even though it lacks the .py suffix. There are two ways of running it. My preferred method is to use the Git Shell, as scrapy has its executable bit set, and can be run without further ado.
The other method, if you want to keep using cmd.exe, is to make a batch file with the following contents:
#echo off
c:\Python27\python c:\Python27\Scripts\scrapy %*
Save it in the Scripts directory as scrapy.bat (assuming your PATH now includes C:\Python27;C:\Python27\Scripts), restart cmd.exe, and you should now be able to run it from the command line.
I experienced a similar problem (I'm using a virtual environment in Windows 7).
I noticed that for older versions of scrapy, e.g. pip install scrapy==0.18.4, it automatically creates a scrapy.bat in my virtual environment: {VENV_ROOT_FOLDER}\Scripts\scrapy.bat
But if I use the latest scrapy (currently version 0.24.2), the scrapy.bat is missing.
I wanted to use the latest scrapy version, so what I did is to put a copy of scrapy.bat to its Scripts folder and it solves the problem.

Why am I getting this ImportError?

I have a tkinter app that I am compiling to an .exe via py2exe.
In the setup file, I have set it to include lxml, urllib, lxml.html, ast, and math.
When I run python setup.py py2exe in a CMD console, it compiles fine. I then go to the dist folder It has created, and run the .exe file.
When I run the .exe I get this popup window.
(source: gyazo.com)
I then procede to open the Trader.exe.log file, and the the contents say the following;
Traceback (most recent call last):
File "Trader.py", line 1, in <module>
File "lxml\html\__init__.pyc", line 42, in <module>
File "lxml\etree.pyc", line 12, in <module>
File "lxml\etree.pyc", line 10, in __load
File "lxml.etree.pyx", line 84, in init lxml.etree (src\lxml\lxml.etree.c:190292)
ImportError: cannot import name _elementpath
Included here is a copy of my setup.py file.
Please help me find the problem here. Thanks in advance.
Looks like py2exe doesn't realize it should include the lxml._elementpath module, which is conditionally imported by lxml.etree. You can tell it to include that module explicitly with the includes keyword argument in your setup.py.
setup(
options={'py2exe': {"includes": ["lxml._elementpath"]}}
)
Py2exe has made documentation of this error on this page: http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules
They also offer a working solution.

Using kinterbasdb with py2exe

I'm trying to create executable program with py2exe. I get the following error message when kinterbasdb is imported:
Traceback (most recent call last):
File "AlarmReporter.py", line 13, in <module>
File "zipextimporter.pyo", line 82, in load_module
File "kinterbasdb\__init__.pyo", line 119, in <module>
File "zipextimporter.pyo", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading kinterbasdb\_kinterbasdb.pyd
Here's my very basic setup.py for py2exe:
from distutils.core import setup
import py2exe
import sys
setup(
options={'py2exe': dict(bundle_files=1, optimize=2)},
console=['AlarmReporter.py'],
zipfile=None,
)
I'm having problem understanding the error message and have no idea how to fix it.
Try to exclude libfbclient dll
Error while transforming .py to .exe
If that doesn't work , try to use the new fdb driver (the future replacement of kinterbasdb)
http://permalink.gmane.org/gmane.comp.db.firebird.python/104
(it doesn't need compiling only the libfbclient.dll)
Another option is to use the pure driver that doesn't need no dll and no c generated binary
https://github.com/nakagami/pyfirebirdsql
But you will use it at your own risk ;)

Py2Exe Error: Win32com.client causes errors when trying to run created executable

My script that I'm trying to create into an executable contains the following imports:
import csv, time, BeautifulSoup, sys, mechanize, os, traceback, win32com.client as win32
My setup.py looks like this:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
console = [{'script': "tool.py"}],
zipfile = None,
)
The .exe of my program is created successfully, however when I try to run it I receive the following errors:
Traceback (most recent call last):
File "tool.py", line 1, in <module>
File "zipextimporter.pyc", line 82, in load_module
File "win32com\__init__.pyc", line 5, in <module>
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading win32api.pyd
Surprisingly, it compiles into an .exe fine if I use bundle_files: = 3 however I need this program to be in one executable, not multiple files. I've read this from the py2exe website but I'm not sure if that's what I need to do/use. If that is the answer I'm looking for, I don't know how to use that or what to do with it. Please explain.
Any help is greatly appreciated!
This was solved by upgrading to Python 2.7. I originally had Python 2.6 installed but the update solved this issue.

"AttributeError: fileno" when attemping to import from pyevolve

I just installed Pyevolve using easy_install and I am getting errors trying to run my first program. I first tried copy and pasting the source code of the first example but this is what I receive when I attempt to run it:
Traceback (most recent call last):
File "/home/corey/CTest/first_intro.py", line 3, in
from pyevolve import G1DList
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/init.py", line 15, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/Consts.py", line 240, in
import Selectors
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/Selectors.py", line 12, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/GPopulation.py", line 11, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/FunctionSlot.py", line 14, in
File "/usr/lib/python2.6/site-packages/Pyevolve-0.5-py2.6.egg/pyevolve/Util.py", line 20, in
AttributeError: fileno
I am running python 2.6 on Fedora 11 X86_64.
Edit: After looking into it more if I run python from the command line it works but it only fails when I'm running IDLE.
Have you tried to check out the Development version ? It's near of the RC1, so it is stable right now:
svn co https://pyevolve.svn.sourceforge.net/svnroot/pyevolve/trunk pyevolve
Your problem seems to be the paths, try uncompressing the "egg" file and put the "pyevolve" directory in the site-packages or inside your application directory.

Categories