I wrote a program it works fine without any errors when I run it from the python interpreter, I then used py2exe to turn it in to an .exe but when I run it it does'nt work anymore... I get this error:
Traceback (most recent call last):
File "pass.py", line 1, in <module>
File "dropbox\__init__.pyc", line 3, in <module>
File "dropbox\client.pyc", line 22, in <module>
File "dropbox\rest.pyc", line 26, in <module>
File "pkg_resources.pyc", line 950, in resource_filename
File "pkg_resources.pyc", line 1638, in get_resource_filename
NotImplementedError: resource_filename() only supported for .egg, not .zip
Am I supposed to do something when using py2exe when I have downloaded modules imported into the program?
these are the modules imported :
import dropbox
import os
import getpass
from time import sleep
please help !
I fixed this problem using the solution found here
basically you modify ~line 26 in rest.py found in the dropbox library
to this:
try:
TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt')
except:
# if current module is frozen, use library.zip path for trusted-certs.crt path
# trusted-certs.crt must exist in same directory as library.zip
if hasattr(sys,'frozen'):
resource_name = sys.prefix
resource_name.strip('/')
resource_name += '/trusted-certs.crt'
TRUSTED_CERT_FILE = resource_name
else:
raise
and then place the trusted-certs.crt file also found in the dropbox library in the same folder as your executable
Related
Note: Please don't comment here that Python 2.7 is depreciated. I already know this. I need to get this working first before migrating to 3.x.
On Windows 10, I had installed (and running correctly) both Python 2.7 and Python 3.7. Since I only needed Python 2.7, I uninstalled Python 3.7 (and manually deleted respective packages installed under .\Python37*) as well as the virtual environment directory below. I have no idea if that virtual environment was associated with Python 2.7 or Python 3.7:
C:\Users\MKANET\Envs\MKA.NETT
After I rebooted, to my horror, every time I run a Python 2.7 script, I get a whole bunch of ambiguous traceback errors when trying to import modules I had installed with PIP (for Python 2.7). However, I don't have issues importing the modules like sys, json (packages that come preinstalled with Python 2.7).
When executing script below from Windows command-line:
& C:/Users/MKANET/AppData/Local/Programs/Python/python27/python.exe c:/Users/MKANET/OneDrive/Dev/Projects/Python/test2.py
...I get a bunch of ambiguous traceback errors:.
Traceback (most recent call last):
File "c:/Users/MKANET/OneDrive/Dev/Projects/Python/test2.py", line 3, in <module>
from pypsexec.client import Client
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\pypsexec\client.py", line 8, in <module>
from smbprotocol.connection import Connection, NtStatus
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\smbprotocol\connection.py", line 33, in <module>
from cryptography.hazmat.primitives.ciphers import (
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\hazmat\primitives\ciphers\aead.py", line 10, in <module>
from cryptography.hazmat.backends.openssl import aead
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 16, in <module>
from cryptography import utils, x509
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\__init__.py", line 8, in <module>
from cryptography.x509.base import (
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\base.py", line 18, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\extensions.py", line 26, in <module>
from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\cryptography\x509\general_name.py", line 10, in <module>
from email.utils import parseaddr
File "c:\Users\MKANET\OneDrive\Dev\Projects\Python\email.py", line 11, in <module>
obj = win32com.client.Dispatch("Outlook.Application")
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\MKANET\AppData\Local\Programs\Python\python27\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147221005, 'Invalid class string', None, None)
UPDATE HUGE CLUE:
This is ONLY happens when executing scripts in the below folder:
C:\Users\Michael\OneDrive\Dev\Projects\Python
If I execute a script in any other folder on my C: Drive, modules load perfectly without errors. I don't know what's different about this folder that causes my modules not load. Maybe, there's a file in this folder that causing this?
Since this issue was limited only to scripts inside the below directory:
C:\Users\Michael\OneDrive\Dev\Projects\Python
I was able to narrow the issue down to a file called, email.py. If I tried to import a module for example, requests; for some odd reason an email.pyc would get created; followed by the import module errors. All I did was rename email.py to mail.py.. and, this whole issue finally stopped.
I have no idea why Python 2.7 is sensitive to that file name, but changing it to something else resolved the issue for me. Maybe, someone could comment on why the file name breaks things; especially when I had a __init__.py in the same directory to import another module.
I get an error when I try to start an exe file with pywinauto. This is my code:
from pywinauto.application import Application
app = Application()
app.Start("D:\dragonboy160\dragonboy160.exe")
As far as I know that should work. app = Application().start("") does not work either. I also tried setting the imports like this: from pywinauto import Application I get this error when I run the python file in PyCharm:
"C:\Program Files (x86)\python.exe" D:/dragonboy160/screenview.py
Traceback (most recent call last):
File "D:/dragonboy160/screenview.py", line 2, in <module>
import pywinauto
File "C:\Program Files (x86)\lib\site-packages\pywinauto\__init__.py", line 40, in <module>
from . import findwindows
File "C:\Program Files (x86)\lib\site-packages\pywinauto\findwindows.py", line 42, in <module>
from . import controls
File "C:\Program Files (x86)\lib\site-packages\pywinauto\controls\__init__.py", line 36, in <module>
from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
File "C:\Program Files (x86)\lib\site-packages\pywinauto\controls\uiawrapper.py", line 44, in <module>
from ..uia_defines import IUIA
File "C:\Program Files (x86)\lib\site-packages\pywinauto\uia_defines.py", line 35, in <module>
import comtypes.client
File "C:\Program Files (x86)\lib\site-packages\comtypes\client\__init__.py", line 33, in <module>
gen_dir = _find_gen_dir()
File "C:\Program Files (x86)\lib\site-packages\comtypes\client\_code_cache.py", line 71, in _find_gen_dir
result = os.path.abspath(gen_path[-1])
IndexError: list index out of range
I searched and searched and it seems no other person has had this problem. I also tried opening other .exe files but got the same error. What is causing this error and how can I fix it?
This is an import problem (at the very first line).
This looks like comtypes can't write cached files to Program files without admin privileges. In theory it might be fixed on comtypes side (or by re-installing Python to another folder like C:\Python3x), but you will have to run the script as Administrator anyway because of other OS restrictions (pywinauto will warn about insufficient rights in nearest future, now it's silent).
I had the same problem and I managed to have it fixed by disabling UAC from Windows.
I'm trying to make an exe file using py2exe. The problem is that when I try to run created exe file, it returns that it cannot import name chardet.
Traceback (most recent call last):
File "orsr_parser.py", line 10, in <module>
File "requests\__init__.pyc", line 58, in <module>
File "requests\utils.pyc", line 26, in <module>
File "requests\compat.pyc", line 7, in <module>
ImportError: cannot import name chardet
I use requests module in one of the py files in the program.
Setup.py:
from distutils.core import setup
import py2exe
packages = ['requests']
setup(console=['my_script.py'])
Do you know where could be the problem? Is there something with setup.py file?
EDIT: There is only one answer for this problem: Stackoverflow answer, but I probably don't get it. There is no directory called requests in my project.
I am using python, and I am running the script that use the file in the same directory, but it keeps giving me the error saying that there is no such file.
I am using that script file as a module to enable my other script file, by the way. The file I am using as a module is from the github project : https://github.com/nik0spapp/unsupervised_sentiment (unsupervised sentiment analysis)
Traceback (most recent call last):
File "sentiment_analysis.py", line 21, in <module>
import sentiment as unsupervised_sentiment
File "/Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/sentiment.py", line 20, in <module>
from hp_classifiers import HpObj, HpSubj
File "/Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/hp_classifiers.py", line 16, in <module>
from lexicon import Lexicon
File "/Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/lexicon.py", line 17, in <module>
from datasets.emoticons_patch import patch_emoticons
File "/Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/datasets/emoticons_patch.py", line 23, in <module>
emoticons_file = open("emoticons.data","r")
IOError: [Errno 2] No such file or directory: 'emoticons.data'
Any help would be the best to me as of now. Thanks!
It's possible when using relative paths instead of absolute paths in your programs that your code is looking for a file (like "emoticons.data") in the directory of the executing program (in this case, the script, NOT the module.) I would first try changing all file-paths to absolute paths in the program, or put the "emoticons.data" in your executing directory.
There is a discrepancy between your error (emoticons_file = open("emoticons.data","r")) and the source code you reference (unsupervised_sentiment/datasets/emoticons_patch.py:23 is emoticons_file = open("datasets/emoticons.data","r")). but the basic problem is the same. The module attempts to open the file using a relative path name, which only works if you are executing from the project's directory.
If you update to the code I found in the repo, you must cd to /Users/chlee021690/Desktop/Programming/Python/Recommender System/unsupervised_sentiment/ to run it.
To me, this is broken and the project maintainers should fix it.
I'm trying to convert a python script to a stand-alone executable using py2exe. The script is built mostly using arcpy, with a Tkinter GUI.
The setup.py script is as follows:
from distutils.core import setup
import py2exe
script = r"pathtoscript.py"
options = {'py2exe':{
"includes": ['arcpy', 'arcgisscripting'],
"packages": ['arcpy', 'arcgisscripting'],
"dll_excludes": ["mswsock.dll", "powrprof.dll"]
}}
setup(windows=[script], options=options)
When run, setup.py creates the .exe as expected, but when I try to run the executable, I get the following error:
Traceback (most recent call last):
File "autolim.py", line 7, in <module>
File "arcpy\__init__.pyc", line 21, in <module>
File "arcpy\geoprocessing\__init__.pyc", line 14, in <module>
File "arcpy\geoprocessing\_base.pyc", line 14, in <module>
File "arcgisscripting.pyc", line 12, in <module>
File "arcgisscripting.pyc", line 10, in __load
ImportError: DLL load failed: The specified module could not be found.
I use python 2.7 and arcgis 10.1 - feel free to ask if I've forgotten any useful information.
Can anyone tell me what I need to do to get the executable working properly?
Many thanks!
I had the same problem...
Since your users will have python/arcpy installed on their machines have your arcpy scripts in a data_files directory.
setup(windows=[script], data_files=[('scripts', glob(r'/path/to/scripts/*.py')], options=options)
Then call them using subprocess.Popen
import subprocess
subprocess.Popen(r'python "%s\scripts\autolim.py"' % self.basedir)
Popen is non-blocking so it won't freeze your GUI while the arcpy script runs.
If you want to print any print statements in your arcpy script change to
p = subprocess.Popen(r'python "%s\scripts\autolim.py"' % self.basedir, stdout=subprocess.PIPE)
while True:
line = p.stdout.readline()
if not line:
break
sys.stdout.write(line)
sys.stdout.flush()
I suggest you see this step: https://community.esri.com/t5/python-questions/using-py2exe-with-arcpy-it-can-be-done-easily/td-p/360520
You must add exclude in setup options and copy the site-packages path.
I have tried it and it works.