PIP raising SyntaxError from command line - python

I have attempted to install PIP using the following commands:
sudo yum install python-setuptools
sudo easy_install pip
sudo pip install supervisor
As it installed, a number of syntax errors were raised from the second and third lines. The errors are fairly similar to that below, so for brevity I'll omit here, but let me know if having those will help. There are a lot.
When I run any pip command, I get SyntaxErrors:
# pip
Traceback (most recent call last):
File "/usr/bin/pip", line 7, in ?
sys.exit(
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 236, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 2097, in load_entry_point
return ep.load()
File "/usr/lib/python2.4/site-packages/pkg_resources.py", line 1830, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/lib/python2.4/site-packages/pip-8.1.1-py2.4.egg/pip/__init__.py", line 208
except PipError as exc:
^
SyntaxError: invalid syntax
I am running CentOS release 5.11 (Final) and Python 2.4.3 (#1, Jan 9 2013, 06:47:03). Note, these are managed by WHM.
I have re-installed PIP using python get-pip.py --ignore-installed, but get the same result.
Is this a Python version conflict? Is my version of Python too old and the syntax in the PIP scripts different? What should I do?

except PipError as exc: isn't a valid Python 2.4 syntax (it should be except PipError, exc).
I don't think pip is meant to work with Python 2.4. Try this question for installing PIP 1.1, which is compatible with that version of Python:
Installing Pip on 2.4

As the above answer describes, you've run into version conflicts between pip and python. You're using an old version of CentOS with an old version of python 2, which makes things worse.
Updating the system environment with 'sudo pip' has a very high risk of creating version problems with system utilities. You can, for instance, break yum, and be forced to update your system with rpm commands. You need to install a recent version of python (preferably python 3) as an alternate install in /usr/local/bin or in a user directory.
Then I highly recommend using a virtual environment (https://virtualenv.pypa.io/en/latest/, or a built-in capability in python 3.5). That lets you set up your own python executable, libraries, and installed packages any way you like, without risk of affecting your entire system. It's a minor setup pain, but it makes most of the problems just vanish.

Related

Tried to upgrade pip, but error 'WinError 5' showed up

I've found a problem with pip and can't do anything with it anymore.
I'm on a Windows 7 computer and have a Dutch language (maybe it will occur problems with reading)
I did use pip version 8.1.1, but there's a newer version, 9.0.1. I installed it using 'pip install --upgrade pip' and he's doing pretty well so it uninstalled the previous version of pip and then the problem came. Now I can't use pip as well. When I try to install or upgrade my system says: 'ImportError: No module named pip'.
I had this problem somewhere in 2016 and never found an answer, so I installed Python again on my computer. I hope there's a better way to do this instead of install whole Python and all those modules again.
So for me is this a bit strange, I hope anyone know this problem and knows a way to fix this. Beneath I'll show up the texts in the command prompt.
Code:
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' comm
and.
D:\PythonProjects\Python Crash Course\learning_log\ll_env\Scripts>pip install --
upgrade pip
Collecting pip
Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 8.1.1
Uninstalling pip-8.1.1:
Exception:
Traceback (most recent call last):
File "C:\Users\Pascal\AppData\Local\Programs\Python\Python35\lib\shutil.py", l
ine 538, in move
os.rename(src, real_dst)
OSError: [WinError 17] Het systeem kan het bestand niet verplaatsen naar een and
er station: 'd:\\pythonprojects\\python crash course\\learning_log\\ll_env\\scri
pts\\pip.exe' -> 'C:\\Users\\Pascal\\AppData\\Local\\Temp\\pip-0hagtsau-uninstal
l\\pythonprojects\\python crash course\\learning_log\\ll_env\\scripts\\pip.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\pythonprojects\python crash course\learning_log\ll_env\lib\site-packa
ges\pip\basecommand.py", line 209, in main
File "d:\pythonprojects\python crash course\learning_log\ll_env\lib\site-packa
ges\pip\commands\install.py", line 317, in run
File "d:\pythonprojects\python crash course\learning_log\ll_env\lib\site-packa
ges\pip\req\req_set.py", line 726, in install
File "d:\pythonprojects\python crash course\learning_log\ll_env\lib\site-packa
ges\pip\req\req_install.py", line 746, in uninstall
File "d:\pythonprojects\python crash course\learning_log\ll_env\lib\site-packa
ges\pip\req\req_uninstall.py", line 115, in remove
File "d:\pythonprojects\python crash course\learning_log\ll_env\lib\site-packa
ges\pip\utils\__init__.py", line 267, in renames
File "C:\Users\Pascal\AppData\Local\Programs\Python\Python35\lib\shutil.py", l
ine 553, in move
os.unlink(src)
PermissionError: [WinError 5] Toegang geweigerd: 'd:\\pythonprojects\\python cra
sh course\\learning_log\\ll_env\\scripts\\pip.exe'
D:\PythonProjects\Python Crash Course\learning_log\ll_env\Scripts>pip freeze > r
equirements.txt
Traceback (most recent call last):
File "C:\Users\Pascal\AppData\Local\Programs\Python\Python35\lib\runpy.py", li
ne 184, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\Pascal\AppData\Local\Programs\Python\Python35\lib\runpy.py", li
ne 85, in _run_code
exec(code, run_globals)
File "D:\PythonProjects\Python Crash Course\learning_log\ll_env\Scripts\pip.ex
e\__main__.py", line 5, in <module>
ImportError: No module named 'pip'
Not sure how many people will be drawn to this note, however, if you find yourself in the scenario where the pip install, terminal within PyCharm install, Python Package install, etc. methods are not working and you are receiving the errors that pygame is installed in Conda but module not recognized in PyCharm; it is most likely due to conflicting Python versions having been installed as PyCharm and Conda are both IDEs and you can have overlapping versions of Python installed.
If this is the case, you will need to uninstall all of the versions of Python and Anaconda along with PyCharm. Then once reinstalled, if PyCharm doesn't recognize itself as a Python Interpreter, then add an interpreter and run as a virtual environment. At this stage, you should be able to use the python packages section to install PyGames without issue. You may be able to get by without uninstalling other IDEs however I find that a full purge is full proof.
Hope this helps
This is related to disk drives on Windows. Pip downloads the new files to your current drive (D:) and then tries to move them over to the system files (on C:) and fails.
(See https://github.com/pypa/pip/issues/2824)
Could you run
python -m pip install -U pip
or is pip completely gone?
If it's gone then you would have to re-install it. Maybe re-installing all of Python is easier although probably more time consuming.

Python 3.5 pip version conflict with python 2.7

I am trying to install a software using pip install and my python and pip versions are 3.5. but when I run sudo pip install -e . I get the following error.
Traceback (most recent call last):
File "/usr/local/bin/pip3.5", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/lib/python2.7/dist-packages/distribute-0.6.14-py2.7.egg/pkg_resources.py", line 2675, in <module>
parse_requirements(__requires__), Environment()
File "/usr/local/lib/python2.7/dist-packages/distribute-0.6.14-py2.7.egg/pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==8.1.0
Why Do I get an error with python 2.7 and please some one could sortout my issue.
Your pip version and python versions are separate. It looks like your package requires exactly pip 8.1.0. You have to either upgrade/downgrade to that version first, or modify the software to work with whichever pip you have available.
Also, it may be easier to install the software in a virtual environment rather than system/global one. Changing the system version of pip may break either current apps, or the future pip package updates.

CentOS 6.6 by default uses Python 2.6, which throws a syntax error when running Swift commands

I need to use CentOS 6.6 for a project which comes with Python 2.6 by default. When I install Swift it places the install inside /usr/lib/python2.6/site-packages/swiftclient/, so if I do a 'make altinstall' to install Python 2.7 or 3.3 it still runs with Python 2.6.
I read from other similar questions that trying to just install 2.7 or 3.3 on top of 2.6 will break yum.
The exception that occurs when running 'swift upload..' is:
Traceback (most recent call last):
File "/usr/bin/swift", line 7, in <module>
from swiftclient.shell import main
File "/usr/lib/python2.6/site-packages/swiftclient/__init__.py", line 20, in <module>
from .client import * # noqa
File "/usr/lib/python2.6/site-packages/swiftclient/client.py", line 136
return {key: safe_value(key, val) for (key, val) in headers}
^
SyntaxError: invalid syntax
Is there a way to install swift into the 2.7 directory? Is there some kind of environment variable I can change to point to Python2.7?
Thanks!
Obviously you can install swiftclient into python2.7 directory.
If you have installed python2.7 from sources with make altinstall you can then install pip2.7 and swiftclient
`
wget https://bootstrap.pypa.io/ez_setup.py
/usr/local/bin/python2.7 ez_setup.py
/usr/local/bin/easy_install-2.7 pip
/usr/local/bin/pip2.7 install swiftclient
The big deal though, is that you need to invoke explicitly python2.7 as the interpreter you want to use. Obviously you can set an env variable for it example export PYTHON27=/usr/local/bin/python2.7, but it has to be user/application specific and not system wide, 'cause as you already know, you will break yum dependencies.

pip3 says "resolve pkg_resources.DistributionNotFound: pip==1.3.1"

On OSX 10.7.5, I'm trying to use the pip3 command to install packages to python3. When I try, I get this error message:
zak$ pip3
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/setuptools-1.0-py3.3.egg/pkg_resources.py", line 2793, in <module>
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/setuptools-1.0-py3.3.egg/pkg_resources.py", line 673, in require
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/setuptools-1.0-py3.3.egg/pkg_resources.py", line 580, in resolve
pkg_resources.VersionConflict: (pip 1.4.1 (/usr/local/lib/python3.3/site-packages), Requirement.parse('pip==1.3.1'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/pip3", line 5, in <module>
from pkg_resources import load_entry_point
File "<frozen importlib._bootstrap>", line 1567, in _find_and_load
File "<frozen importlib._bootstrap>", line 1534, in _find_and_load_unlocked
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/setuptools-1.0-py3.3.egg/pkg_resources.py", line 2797, in <module>
File "/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/setuptools-1.0-py3.3.egg/pkg_resources.py", line 576, in resolve
pkg_resources.DistributionNotFound: pip==1.3.1
It looks like setuptools is demanding an old version of pip (I have 1.4.1 installed), but why? How can I fix this?
The problem appears to be that you have two different Python 3.3 installations, and a shared site-packages directory.* And the tool you run as pip3 is from pip 1.3.1, but the modules it uses to do its work come from pip 1.4.1.
The easiest way to solve this, unless you actually need both Python 3.3 installations, is to get rid of both of them completely, then reinstall the one you want.
The following should work (possibly with sudo for some of the commands—or using Finder and letting it tell you whether you need to authenticate).
Note that this will also partially or completely remove any other third-party Python versions (e.g., a python.org 2.7.5), which I don't think is a problem for you, but could be for future readers.
You might want to make a list of all installed packages before uninstalling anything. (I usually do this in the hackiest way possible: fire up ipython, and let it tab-complete an import statement…)
Finally, some of these details will be different for any future readers with similar problems, but the basic ideas should be the same.
brew uninstall python3
rm -rf /Library/Frameworks/Python.framework
rm -rf /usr/local/lib/python*
rm -rf /usr/local/share/python*
Find where in ~/.bash_profile (or ~/.profile or elsewhere) you add the Python paths to your PATH. You may have /usr/local/share/python3 and/or something inside the Python.framework or Cellar/python3. Scrap all that you find.
Fire up a new shell in Terminal.app.
brew doctor, and fix anything that it complains about that seems potentially relevant (the non-Homebrew MacFUSE stuff is fine as-is; the brew prune suggestion is probably worth doing, but doesn't matter here), and run it again to make sure.
brew install python3.
pip3 to reinstall any packages you deleted that you need again.
* Details:
Homebrew Python 3.3 is installed in /usr/local/Cellar/python3/3.3.2/, with various things symlinked into /usr/local/bin and its siblings, and possibly into /Library somewhere.
Another Python 3.3, possibly from the python.org installer, is installed in /Library/Frameworks/Python.framework/Versions/3.3/, with various things possibly symlinked into /usr/local/bin or otherwise added to your PATH.
Both probably include /usr/local/lib/python3.3 in their site-packages search.
After running
pip install --upgrade setuptools
I was able to fix it. But this may not be true for everyone for I am still learning Python.
It seems this was caused by a broken Python installation, I was able to fix it by reinstalling Python with Homebrew.
brew reinstall python3

Why is Python easy_install not working on my Mac?

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 :-)

Categories

Resources