Exe file says - cannot import name chardet - python

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.

Related

py2exe: run the compiled .exe, got error: type object 'pandas._libs.tslib._TSObject' has no attribute...__'

I use py2exe to compile python script. The python script runs without any error before compiling.
below is the setup.py
from distutils.core import setup
import py2exe, sys, os
import matplotlib
import numpy
from glob import glob
sys.argv.append('py2exe')
datafiles = [("Microsoft.VC90.CRT", glob(r'C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_99b61f5e8371c1d4\*.*'))]
datafiles.extend(matplotlib.get_py2exe_datafiles())
setup(windows=['Run.py'], data_files= datafiles, options={"py2exe": {"includes": ["matplotlib"]}})
In the run.py, I imported pandas. Pandas is used in a function as below
import pandas
def PossDist(Iterations, AssumptionFolder, ResultFolder, SampledResult):
SampledLoss = pandas.read_csv(SampledResult)
d= pandas.pivot_table(...)
The compile finished successfully without error.
When I run the compiled run.exe, I got error as below.
Traceback (most recent call last):
File "Run.py", line 6, in
File "xlwings__init__.pyc", line 34, in
File "xlwings\main.pyc", line 1727, in
File "xlwings\conversion__init__.pyc", line 3, in
File "pandas__init__.pyc", line 26, in
Main Features
File "pandas_libs__init__.pyc", line 4, in
File "pandas_libs\tslib.pyc", line 12, in
File "pandas_libs\tslib.pyc", line 10, in __load
File "pandas_libs\tslib.pyx", line 1514, in init pandas._libs.tslib
AttributeError: type object 'pandas._libs.tslib._TSObject' has no attribute 'reduce_cython'
Anyone have any clue?
Is there other way to let others run my python script on pc without python installed?
Thanks,

How I can use 'regex' package in python without installation?

I want to use regex package without installation (neither using pip nor python setup.py install)
For that, I have downloaded the package and kept in the same directory of the file where I am importing regex. The code is given below
import sys
import os
currentdirectory = os.getcwd()
sys.path.append(currentdirectory+"/packages/regex/Python2/")
from regex import *
I am getting following error as _regex extension module is not created.
Traceback (most recent call last):
File "test.py", line 30, in <module>
from regex import *
File "/Users/nilakshi/test_branch/packages/regex/Python2/regex.py", line 387, in <module>
import _regex_core
File "/Users/nilakshi/test_branch/packages/regex/Python2/_regex_core.py", line 21, in <module>
import _regex
ImportError: No module named _regex
How do I create _regex extension module that can be locally used?
Also, can I create _regex extension module file such that I can use the same file in different machines without creating again?

program wont work after being compiled with py2exe

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

ImportError: Module use of python26.dll conflicts with this version of Python

I use Python 3.2.3
Tonight I tried to install requests from http://docs.python-requests.org/en/latest/ by pip and easy_install, but it doesn't work. I have error when trying to import it. So I decided to use standard library urllib.request and see this error again
That is the traceback:
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "E:\Python32\lib\site-packages\requests-1.2.0-py3.2.egg\requests\__init__.py", line 52, in <module>
from . import utils
File "E:\Python32\lib\site-packages\requests-1.2.0-py3.2.egg\requests\utils.py", line 12, in <module>
import cgi
File "E:\Python32\lib\cgi.py", line 38, in <module>
from email.parser import FeedParser
File "E:\Python32\lib\email\parser.py", line 12, in <module>
from email.feedparser import FeedParser
File "E:\Python32\lib\email\feedparser.py", line 27, in <module>
from email import message
File "E:\Python32\lib\email\message.py", line 17, in <module>
from email import utils
File "E:\Python32\lib\email\utils.py", line 28, in <module>
import socket
File "E:\Python32\lib\socket.py", line 46, in <module>
import _socket
ImportError: Module use of python26.dll conflicts with this version of Python.
So how can I fix this?
UPD: Solved. It was bug in SublimeREPL, reinstalled that package.
I had a similar problem when I was using PythonXY. The Spyder was not loading and it turns out another software OpenCAD had installed Python2.6 version and that was not letting my Python27.dll to not work. After uninstalling OpenCAD, I was able to run the software.
I was able to troubleshoot by first searching for python26.dll and found that this file was located in the OpenCAD folder location and that made me realize that this software was causing the issue.

Python, py2exe, & pyopengl ImportError: No module named win32

When I try to build an exe using py2exe, it builds but when i try to run the exe it throws this error:
Traceback (most recent call last):
File "main.py", line 4, in <module>
File "OpenGL\GL\__init__.pyc", line 3, in <module>
File "OpenGL\GL\VERSION\GL_1_1.pyc", line 10, in <module>
File "OpenGL\platform\__init__.pyc", line 35, in <module>
File "OpenGL\platform\__init__.pyc", line 26, in _load
File "OpenGL\plugins.pyc", line 14, in load
File "OpenGL\plugins.pyc", line 28, in importByName
ImportError: No module named win32
It only does this when I use pyopengl, It builds and runs perfectly with pygame and almost any other library/module I have used.
My setup.py script looks like this:
from distutils.core import setup
import py2exe
setup(console=['main.py'])
I am on Windows 7 64bit
Actually, After another hour or so of searching I found the solution!
For anyone else who has this problem: http://www.py2exe.org/index.cgi/PyOpenGL

Categories

Resources