(OSX = Mountain lion) My app in /dist throws the error:
Last login: Wed Aug 28 11:21:29 on ttys001
-MacBook-Pro:~ $ /Users/Desktop/dist/abc.app/Contents/MacOS/abc ; exit;
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/py2app/apptemplate/lib/site.py", line 20, in <module>
import os
File "os.pyc", line 398, in <module>
File "UserDict.pyc", line 83, in <module>
File "_abcoll.pyc", line 11, in <module>
File "/Users/Virendra/Desktop/dist/abc.app/Contents/Resources/abc.py", line 6, in <module>
import psutil
File "build/bdist.macosx-10.8-x86_64/egg/psutil/__init__.py", line 54, in <module>
File "build/bdist.macosx-10.8-x86_64/egg/psutil/_common.py", line 16, in <module>
File "build/bdist.macosx-10.8-x86_64/egg/psutil/_compat.py", line 65, in <module>
File "collections.pyc", line 6, in <module>
AttributeError: 'module' object has no attribute '__all__'
logout
My setup.py (same error even without the - 'import os') looks like:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['abc.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True, 'includes': ['psutil', 'time', 'socket', 'os']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
And the scrip abc.py in question:
from psutil import cpu_times_percent
import socket
import time
serverHost = "localhost"
thisClient = socket.gethostname()
cpuStats = psutil.cpu_times_percent()
print cpuStats
currentTime = int(time.time())
s = socket.socket()
s.connect((serverHost,8080))
command = 'put cpu.usr ' + str(currentTime) + " " + str(cpuStats[0]) + " host="+ thisClient+ "\n"
s.sendall(command)
command = 'put cpu.nice ' + str(currentTime) + " " + str(cpuStats[1]) +" host="+ thisClient+ "\n"
s.sendall(command)
command = 'put cpu.sys ' + str(currentTime) + " " + str(cpuStats[2]) + " host="+ thisClient+ "\n"
s.sendall(command)
command = 'put cpu.idle ' + str(currentTime) + " " + str(cpuStats[3]) + " host="+ thisClient+ "\n"
s.sendall(command)
s.close()
Initially it was 'import psutil' which I changed to the 'from psutil...' as above. Included the 'import os...' here. But all combinations throw the same error. Elsewhere, I have seen 'import psutil' as a standard import and this is no different. What else could the error AttributeError: 'module' object has no attribute '__all__' mean? Thx.
Your script file, abc.py, conflicts with the Python standard library Abstract Base Class module, abc. The simplest solution should be to just change the name of your file to something else.
Related
If I create console_scripts via entry_point in setup.py, then this file gets created:
#!/home/myproject_cok_d/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'mylib','console_scripts','do-magic'
__requires__ = 'mylib'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('mylib', 'console_scripts', 'do-magic')()
)
Unfortunately this script is fragile.
Sometimes I get exceptions like this:
Traceback (most recent call last):
File ".../bin/do-magic", line 6, in <module>
from pkg_resources import load_entry_point
File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2999, in <module>
#_call_aside
File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2985, in _call_aside
f(*args, **kwargs)
File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 3012, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 662, in _build_master
ws.require(__requires__)
File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 970, in require
needed = self.resolve(parse_requirements(requirements))
File ".../local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 856, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'PyPDF2==1.26' distribution was not found and is required by mylib
Is there a way to make my script (do-magic) more mature?
In this case: It does not need PyPDF2.
I ran into the same error. To solve this issue, you must update PYTHONPATH to add the site directory. On Windows you would go to your the command prompt and type this:
set pythonpath=<PATH_TO_SITE_DIR>
And Mac is this:
export PYTHONPATH="${PYTHONPATH}:<PATH_TO_SITE_DIR>"
Here is more information about the error.
I just did a fresh install of python3 (3.6.5_1) on Mac OS (High Sierra) and pip3 does not work. I get the following error with pip3:
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 11, in <module>
load_entry_point('pip==10.0.1', 'console_scripts', 'pip3')()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 476, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2700, in load_entry_point
return ep.load()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2318, in load
return self.resolve()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2324, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python3.6/site-packages/pip/_internal/__init__.py", line 42, in <module>
from pip._internal import cmdoptions
File "/usr/local/lib/python3.6/site-packages/pip/_internal/cmdoptions.py", line 16, in <module>
from pip._internal.index import (
File "/usr/local/lib/python3.6/site-packages/pip/_internal/index.py", line 39, in <module>
from pip._internal.wheel import Wheel, wheel_ext
File "/usr/local/lib/python3.6/site-packages/pip/_internal/wheel.py", line 7, in <module>
import compileall
File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/compileall.py", line 20, in <module>
from concurrent.futures import ProcessPoolExecutor
File "/Library/Python/2.7/site-packages/concurrent/futures/__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "/Library/Python/2.7/site-packages/concurrent/futures/_base.py", line 357
raise type(self._exception), self._exception, self._traceback
^
SyntaxError: invalid syntax
which pip3 returns /usr/local/bin/pip3
I have searched and can't find a solution.
"sudo easy_install pip" fails with the following error:
Traceback (most recent call last):
File "/usr/bin/easy_install-2.7", line 11, in <module>
load_entry_point('setuptools==18.5', 'console_scripts', 'easy_install')()
File "/Users/swastika.singhal/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 572, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Users/swastika.singhal/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2755, in load_entry_point
return ep.load()
File "/Users/swastika.singhal/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2408, in load
return self.resolve()
File "/Users/swastika.singhal/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2414, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 46, in <module>
from setuptools.archive_util import unpack_archive
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/archive_util.py", line 15, in <module>
from pkg_resources import ensure_directory, ContextualZipFile
ImportError: cannot import name ContextualZipFile
The Google solutions did not work for me so far.
This GitHub issue helped me fix it: github.com/PyMySQL/mysqlclient-python/issues/169
Specifically:
There are lines in mysql_config like following:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "
I edited them to:
# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"
I'm trying to install pylint with pip install pylint
But i've got this at the end of installation:
Removing temporary dir c:\users\fixxxer\appdata\local\temp\pip_build_Fixxxer...
Exception:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "C:\Python27\lib\site-packages\pip\req.py", line 1229, in prepare_files
req_to_install.run_egg_info()
File "C:\Python27\lib\site-packages\pip\req.py", line 292, in run_egg_info
logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.setup_py, self.name))
File "C:\Python27\lib\site-packages\pip\req.py", line 265, in setup_py
import setuptools
File "C:\Python27\lib\site-packages\setuptools\__init__.py", line 12, in <module>
from setuptools.extension import Extension
File "C:\Python27\lib\site-packages\setuptools\extension.py", line 7, in <module>
from setuptools.dist import _get_unpatched
File "C:\Python27\lib\site-packages\setuptools\dist.py", line 16, in <module>
from setuptools.depends import Require
File "C:\Python27\lib\site-packages\setuptools\depends.py", line 6, in <module>
from setuptools import compat
File "C:\Python27\lib\site-packages\setuptools\compat.py", line 19, in <module>
from SimpleHTTPServer import SimpleHTTPRequestHandler
File "C:\Python27\lib\SimpleHTTPServer.py", line 27, in <module>
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
File "C:\Python27\lib\SimpleHTTPServer.py", line 204, in SimpleHTTPRequestHandler
mimetypes.init() # try to read system mime.types
File "C:\Python27\lib\mimetypes.py", line 355, in init
db.read_windows_registry()
File "C:\Python27\lib\mimetypes.py", line 259, in read_windows_registry
for ctype in enum_types(mimedb):
File "C:\Python27\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)
Any ideas how can i fix this or some workarounds?
How can i install it manually?
UPDATE.
replacing
default_encoding = sys.getdefaultencoding()
with
if sys.getdefaultencoding() != 'gbk':
reload(sys)
sys.setdefaultencoding('gbk')
default_encoding = sys.getdefaultencoding()
does this:
Cleaning up...
Removing temporary dir c:\users\fixxxer\appdata\local\temp\pip_build_Fixxxer...
Exception:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip\commands\install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "C:\Python27\lib\site-packages\pip\req.py", line 1229, in prepare_files
req_to_install.run_egg_info()
File "C:\Python27\lib\site-packages\pip\req.py", line 292, in run_egg_info
logger.notify('Running setup.py (path:%s) egg_info for package %s' % (self.setup_py, self.name))
File "C:\Python27\lib\site-packages\pip\req.py", line 265, in setup_py
import setuptools
File "C:\Python27\lib\site-packages\setuptools\__init__.py", line 12, in <module>
from setuptools.extension import Extension
File "C:\Python27\lib\site-packages\setuptools\extension.py", line 7, in <module>
from setuptools.dist import _get_unpatched
File "C:\Python27\lib\site-packages\setuptools\dist.py", line 16, in <module>
from setuptools.depends import Require
File "C:\Python27\lib\site-packages\setuptools\depends.py", line 6, in <module>
from setuptools import compat
File "C:\Python27\lib\site-packages\setuptools\compat.py", line 19, in <module>
from SimpleHTTPServer import SimpleHTTPRequestHandler
File "C:\Python27\lib\SimpleHTTPServer.py", line 27, in <module>
class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
File "C:\Python27\lib\SimpleHTTPServer.py", line 204, in SimpleHTTPRequestHandler
mimetypes.init() # try to read system mime.types
File "C:\Python27\lib\mimetypes.py", line 359, in init
db.read_windows_registry()
File "C:\Python27\lib\mimetypes.py", line 263, in read_windows_registry
for ctype in enum_types(mimedb):
File "C:\Python27\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'gbk' codec can't decode bytes in position 4-5: illegal multibyte sequence
Found a problem.
There was a few MIME types with Cyrillic names in
HKEY_CLASSES_ROOT\MIME\Database\Content Type
Removed them and problem was solved.
I had the same error and this helped me https://stackoverflow.com/a/23278373/2571607
Basically, open C:\Python27\Lib\mimetypes.py
replace
‘default_encoding = sys.getdefaultencoding()’
with
if sys.getdefaultencoding() != 'gbk':
reload(sys)
sys.setdefaultencoding('gbk')
default_encoding = sys.getdefaultencoding()
Trying to get it going with Sphinx for the first time, with a clean Sphinx 1.1.3 installation, and shinx-quickstart fails. Should there be any dependencies installed? I tried to pip --force-reinstall sphinx but the result is the same.
myhost:doc anton$ sphinx-quickstart
Traceback (most recent call last):
File "/usr/local/bin/sphinx-quickstart", line 8, in <module>
load_entry_point('Sphinx==1.1.3', 'console_scripts', 'sphinx-quickstart')()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 318, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2221, in load_entry_point
return ep.load()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 1954, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/Library/Python/2.7/site-packages/Sphinx-1.1.3-py2.7.egg/sphinx/quickstart.py", line 19, in <module>
from sphinx.util.osutil import make_filename
File "/Library/Python/2.7/site-packages/Sphinx-1.1.3-py2.7.egg/sphinx/util/__init__.py", line 25, in <module>
from docutils.utils import relative_path
File "/Library/Python/2.7/site-packages/docutils-0.9-py2.7.egg/docutils/utils/__init__.py", line 19, in <module>
from docutils.io import FileOutput
File "/Library/Python/2.7/site-packages/docutils-0.9-py2.7.egg/docutils/io.py", line 18, in <module>
from docutils.error_reporting import locale_encoding, ErrorString, ErrorOutput
File "/Library/Python/2.7/site-packages/docutils-0.9-py2.7.egg/docutils/error_reporting.py", line 47, in <module>
locale_encoding = locale.getlocale()[1] or locale.getdefaultlocale()[1]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 496, in getdefaultlocale
return _parse_localename(localename)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/locale.py", line 428, in _parse_localename
raise ValueError, 'unknown locale: %s' % localename
ValueError: unknown locale: UTF-8
I was getting the same issue in Mac OS X Snow Leopard. It seems to be an issue with Terminal.app.
Please add the following to your $HOME/.bash_profile
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Do
source $HOME/.bash_profile
and try. This will solve the issue.