Why is Python easy_install not working on my Mac? - python

I have a Mac running Python 2.6. When I try to use easy_install I get this message:
/usr/bin/easy_install-2.6:7: UserWarning: Module pkg_resources was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
from pkg_resources import load_entry_point
/usr/bin/easy_install-2.6:7: UserWarning: Module site was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
from pkg_resources import load_entry_point
Traceback (most recent call last):
File "/usr/bin/easy_install-2.6", line 10, in <module>
load_entry_point('setuptools==0.6c9', 'console_scripts', 'easy_install')()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 271, in load_entry_point
return False
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 2173, in load_entry_point
deps = []
ImportError: Entry point ('console_scripts', 'easy_install') not found
I am very confused by this and I want to know how I can fix this. Previously I didn't get this message, then after installing pip and uninstalling it, easy_install no longer works. I was wondering how I could fix this, or restore the default Python or easy_install setting on Mac.

Check your /usr/bin and /usr/local/bin for easy_install installations and remove any old script:
sudo rm -f /usr/bin/easy_install*
sudo rm -f /usr/local/bin/easy_install*
Download and run distribute:
curl -O https://svn.apache.org/repos/asf/oodt/tools/oodtsite.publisher/trunk/distribute_setup.py
sudo python distribute_setup.py
sudo rm distribute_setup.py
Try again, and enjoy. E.g.:
sudo easy_install pip

I suspect the easiest way you can get easy_install working again is to install distribute, which is an improved version of distutils that bundles it's own version of easy_install. Installation is simple:
curl -O http://python-distribute.org/distribute_setup.py
/usr/bin/python2.6 distribute_setup.py

I had the same problem just after installing the new Operating System (Lion OSX).
After install python and execute it
sudo easy_install ipython
ipython
I got the following error:
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 8, in <module>
load_entry_point('ipython==0.10.2', 'console_scripts', 'ipython')()
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 2220, in load_entry_point
raise ImportError("Entry point %r not found" % ((group,name),))
ImportError: Entry point ('console_scripts', 'ipython') not found
Then I realize it was a permission problem. If I execute the ipython script as sudo it worked.
sudo ipython
So I changed the ownership from root to my user () of the folder /Library/Python/2.7/site-packages/
sudo chown -R <your_user>:wheel /Library/Python/2.7/site-packages/
Use change ownership only if you don't have several accounts that uses python.
I hope it work for you.
Best

Your setuptools installation is broken. The easy_install-2.6 script in your /usr/bin directory, is only a wrapper that loads the actual easy_install module in your Python installation, and the latter is missing. Presumably uninstalling pip either broke the pointer to it (usually in the form of a .pth file in your site-packages directory) or removed the whole package but didn't remove the /usr/bin/easy_install-2.6 wrapper script.
Your best bet is to re-install setuptools from scratch again, by following the instructions on the setuptools PyPI page.

I had the same problem, I suspect caused by my installation of Homebrew which apparently installs its own version of easy_install blindly and screws up whatever you're currently running (enough times for homebrew to recognize it as a problem). I found my solution here Upgraded Python on Snowleopard Using Homebrew now pip and easy_install don't work
While I'm actually on Lion, it still fixed my problem. You just download ez_setup.py from http://pypi.python.org/pypi/ez_setup - run ez_setup.py through terminal and you're off to the races.

I had a similar error message after following similar steps. I suspect it's because I tried to install the distribute module, and it tried to install a new version of setuptools which
didn't quite work because it failed to correctly override the Mac OS X supplied setuptools. But that's only a suspicion.
I fixed my problem by doing the following. I found that the directory /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python
had 4 files with .OLD in the name. When I did a compare with similarly named files without the .OLD from when things worked (via Time Machine) I found that they were the same except for the name. So I did the following renames:
setuptools.OLD.1305936263.57 ->
setuptools
setuptools-0.6c9-py2.6.egg-info.OLD.1305936263.57 -> setuptools-0.6c9-py2.6.egg-info pkg_resources.py.OLD.1305936263.57
-> pkg_resources site.py.OLD.1305936263.59 -> site.py
I had to use the command line and sudo mv because the files are owned by root. For example: sudo mv setuptools.OLD.1305936263.57 setuptools. You'll have to enter your password.
The other thing I did was clean the /Library/Python/2.6/site-packages directory. I used Time Machine to set it back to its pre-messed up state. If you don't have Time Machine, then you should be able to recover if you delete any files or folders beginning with distribute, easy-install, pip, pkg_resources, setuptools and site.
If that doesn't do the trick, uninstall any modules you can from that directory. For example use pip uninstall if you installed modules with pip. The reason to do this is that installation can copy files into usr/local/bin and other places that pip will remove for you.
Next it's time to remove any remaining modules. Rename the folder (in case there's something you want later) and make a new empty one.
Reinstall the modules you want and with a little luck you're back in business...

Martijn Pieter's answer is correct.
Go to http://pypi.python.org/pypi/setuptools#downloads
Download setuptools-0.6c11-py2.7.egg
From your downloads directory run: sudo ./setuptools-0.6c11-py2.7.egg
Done :-)

Related

how to install selinux package in a venv, from a self contained python installation

I have built python3.8.12 from source and installed it in /python3 on a machine with no other python anywhere. there are no "system" packages. (it is rocky8.5 linux)
Now I create and activate a venv from that python:
/python3/bin/python -m venv myvenv
source myvenv/bin/activate
Now I install packages in this venv from a local repository
pip install -r requirements.txt --index-url=file:///python3/pypkgs/simple
The repository was built with pip2pi. this is all being designed for full airgap deployments.
Now I cannot import selinux as it is apparently not aware of the selinux in the venv, and is instead searching the system.
(myvenv) [root#node1]# python -c "import selinux"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/root/myvenv/lib/python3.8/site-packages/selinux/__init__.py", line 104, in <module>
check_system_sitepackages()
File "/root/myvenv/lib/python3.8/site-packages/selinux/__init__.py", line 100, in check_system_sitepackages
raise Exception(
Exception: Failed to detect selinux python bindings at ['/python3/lib/python3.8/site-packages']
I use the selinux package as an example because it is the issue I am currently faced with. Not sure if this is a wider problem yet. Haven't tested exhaustively, but have not had issue with any other package.
Ok I guess I got it working. Not sure how horrendous of a fix this is.
First, I installed selinux to the system /python3 (apparently you can't use selinux within a venv - has to be system level?)
And then I hardcoded my /python3/bin/python to this line: https://github.com/pycontribs/selinux/blob/321d66619ed59bec00a9dc6216ce417d7befec41/selinux/__init__.py#L76

Python Error : No module named pkg_resources

I would like to use Python3.7 on MacOS
I already Python 2.7 version.
I created an alias on .bash_profile, alias python="/usr/local/bin/python3.7" then source ~/.bash_profile.
So I deleted Python2.7 to /usr/local/lib/
Now, when I try to execute pip install PySide2, I have an error :
Traceback (most recent call last):
File "/usr/local/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
I think this error has happened since I deleted Python2.7
Someone can help me to resolve my error ?
Thank you !
pyinstaller 3.6 is incompatible with setuptools 45.1.0 on python 3.7.*, should be downgraded to 45.0.0
pip install setuptools==45.0.0
can also be fixed with passing/adding hidden_imports 'pkg_resources.py2_warn' to pyinstaller spec
Issue and solutions are tracked here: https://github.com/pypa/setuptools/issues/1963
I found solution from here.
In my case, I open hook-pkg_resources.py file from the following directory:
~/.local/lib/python3.6/site-packages/PyInstaller/hooks/
After that I added this line of code:
hiddenimports.append('pkg_resources.py2_warn')
between these two lines of code:
hiddenimports = collect_submodules('pkg_resources._vendor')
and
excludedimports = ['__main__']
After that, I ran PyInstaller again and the resulted executable worked like charm.
This is caused because of a broken setuptools package, you just need to reinstall it.
For most operating systems: pip install setuptools
Linux: apt-get install python-setuptools or yum install python-setuptools
Stumbled uppon this answer first on google when searching for this error code, so for future reference ill just leave a link to this issue that solved my problem:
https://stackoverflow.com/a/59979390/10565375
tldr:
pyinstaller --hidden-import=pkg_resources.py2_warn example.py

How to fix Python ValueError:bad marshal data?

Running flexget Python script in Ubuntu, I get an error:
$ flexget series forget "Orange is the new black" s03e01
Traceback (most recent call last):
File "/usr/local/bin/flexget", line 7, in <module>
from flexget import main
File "/usr/local/lib/python2.7/dist-packages/flexget/__init__.py", line 11, in <module>
from flexget.manager import Manager
File "/usr/local/lib/python2.7/dist-packages/flexget/manager.py", line 21, in <module>
from sqlalchemy.ext.declarative import declarative_base
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/__init__.py", line 8, in <module>
from .api import declarative_base, synonym_for, comparable_using, \
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/declarative/api.py", line 11, in <module>
from ...orm import synonym as _orm_synonym, \
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/__init__.py", line 17, in <module>
from .mapper import (
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/mapper.py", line 27, in <module>
from . import properties
ValueError: bad marshal data (unknown type code)
If you get that error, the compiled version of the Python module (the .pyc file) is corrupt probably. Gentoo Linux provides python-updater, but in Debian the easier way to fix: just delete the .pyc file. If you don't know the pyc, just delete all of them (as root):
find /usr -name '*.pyc' -delete
There also appears to have been some sort of regression in setuptools with use with python 3.7. See for an example - https://github.com/pypa/setuptools/issues/1257
Forcing reinstallation of setuptools fixed this issue for me.
sudo pip3 install --upgrade --force-reinstall setuptools
Just delete
/usr/local/lib/python2.7/dist-packages/sqlalchemy/orm/properties.pyc
it is corrupt as the text indicates. You'll probably have to do so as root.
After that start (again as root) run python (2.7):
/usr/bin/python -c "import sqlalchemy.orm.properties"
to recreate this .pyc file.
If you don't recreate the .pyc file, your program starts slower than necessary as the .py file takes longer to load than the .pyc (and a normal user cannot write the .pyc file).
This can happen if you have Python 2.7 .pyc files and you try to load them using Python 3.5. In my case this was a third-party tarball that erroneously included pre-compiled Python 2.7 .pyc files along with the source code.
I get this error in Ubuntu 18.04 Raspberry Pi 3 when I trying update my system typing sudo apt-get update and solve this error just typing:
sudo find /usr -name '*.pyc' -delete
This is remove all .pyc file in my system. Now I typing again sudo apt-get update && sudo apt-get upgrade and I get my update without thie error marshal-data
I resolved a similar error by un-installing and re-installing the Python application I was using, and all dependencies, using the system package manager.
In my case I was using awscli on Debian 9 and the error was "ValueError: bad marshal data (set size out of range)".
I ran as root:
apt-get purge awscli
apt-get autoremove
apt-get install awscli
And then the error was fixed.
I could imagine cases where the broken package might not get removed (for example because it was marked as manually installed, or was a dependency of another application still installed), in those cases this action may not resolve the error. However I thought I should try this way before manually deleting .pyc files the system installed, and I got lucky.
I also got this problem in Windows environment(win 10).
I fixed it by going to the Settings and repairing Python 3.7 with its installer.
Everything works fine since then.
As far as I could recall, I had kept a dash server running when my computer went to hibernation.
Maybe the damage was done in the hibernating process somehow.
I solved this problem by the following procedure :
In the error code message, you can see
from sqlalchemy.ext.declarative import declarative_base cause this error.
So just pip uninstall sqlalchemy and pip install sqlalchemy, problem solved.
It may be because of the damage of the library. Try re-install the package.
I had the same error in a conda environment which traced back to importing the matplotlib package.
simply pip uninstall matplotlib and then pip install matplotlib solved the problem.

Installing eyed3 in windows

trying to install eyed3 under python 2.7.5
I have done a google search and have been following what I found to install eyed3. The instructions were as follows
extract the zip file to a temp folder (filename eyeD3-0.7.3.zip) I
did using a temp folder on my desktop.
In the eyeD3 folder (under src) rename the init.py.in to
setup.py. I did not find _init++.py.in in the eyed3 folder, but
init_.py was,so I assumed this latest version used that file.
In the main folder (I assume eyeD3-0.7.3) run python setup.py.in
install. setup.py.in didnot exist, but I ran it anyway and got the
expected file not found message, however, setup.py did exist so I
executed python setup.py install and got the following Traceback
Traceback (most recent call last): File "C:\Users\Me\Desktop\New
folder\eyeD3-0.7.3\setup.py", line 10, in <module>
paver.tasks.main() File "paver-minilib.zip\paver\tasks.py", line
883, in main File "paver-minilib.zip\paver\tasks.py", line 851,
in _launch_pavement File "pavement.py", line 28, in <module>
import setuptools ImportError: No module named setuptools
a cmd line search of the python 2.7.5 dir and sub-directories did not find setuptools.py, however I did find the following two files
setuptools_build_ext.py and setuptools_extension.py.
Do I need to rename one of these files or do you know what I am doing wrong or what the fix would be?
Thank you
Depending on where you got your Python from, it may not have come with setuptools. In particular, it does not come in the standard Windows installers from Python.org.
Some packages' setup.py scripts have special code that tries to download and install setuptools (or distribute) if it's missing, or that bundles in just enough of setuptools into the package itself. But not all of them do.
The answer is to install setuptools yourself.
While you're at it, you probably want to also install pip, and then you can just pip install . from within the directory, or pip install eyeD3-0.7.3.zip without unzipping, or even just pip install eyeD3 without even downloading. (Among other things, it will also download and install any dependencies that eyeD3 might need.)
In fact, the eyeD3 installation docs explicitly say "Stable releases of eyeD3 are best installed via pip…".

python import error in gzip.py ; where is zlib

I am running Ubuntu 12.10 that has python 2.7 as its default. I have installed python 3.3 in /opt/python3.3 (using ./configure --prefix=/opt/python3.3) and have created a symlink /usr/bin/python33 that points to the executable in /opt. There is already a symlink /usr/bin/python3 that points to the python 3.2 (actually it points to python3.2mu: if you can explain as a side note as to why this 'mu' is included :) ) installation that came with the ubuntu installation.
I installed distribute tools using python3 without any problems. But when I tried the same thing with python33 it gave me the following error:
ankur#junk-mechanism:~$ sudo python33 distribute_setup.py
Extracting in /tmp/tmp685lyf
lzma module is not available
not a bzip2 file
gzip module is not available
bad checksum
Traceback (most recent call last):
File "distribute_setup.py", line 550, in <module>
sys.exit(main())
File "distribute_setup.py", line 547, in main
return _install(tarball, _build_install_args(options))
File "distribute_setup.py", line 78, in _install
tar = tarfile.open(tarball)
File "/opt/python3.3/lib/python3.3/tarfile.py", line 1578, in open
raise ReadError("file could not be opened successfully" + str(name) + repr(fileobj))
tarfile.ReadError: file could not be opened successfully/home/ankur/distribute-0.6.35.tar.gzNone
So in tarfile.py, the classmethod Tarfile.open calls the class method Tarfile.gzopen where the module gzip is imported:
try:
import gzip
gzip.GzipFile
except (ImportError, AttributeError):
raise CompressionError("gzip module is not available")
The error raised here is ImportError because gzip.py has an import zlib which it cant find. But even the other installations of python (2.7 and 3.2) dont contain zlib in the respective standard lib /usr/lib/pythonx.x/lib/. So what is the difference?
It sounds like you didn't build everything because of missing dependencies. You can try getting the missing dependencies and rebuilding. To get the missing dependencies, I'd just work from what Python 3.2 requires and do:
sudo apt-get build-dep python3
Then you can reconfigure and rebuild Python 3.3 to get all the required modules.
Another option is to use the dead snakes ppa:
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python3.3
I usually install the -dev package too so that I can install packages that have C extension modules:
sudo apt-get install python3.3-dev

Categories

Resources