Pip not installing correctly

2019-07-11 07:27发布

问题:

I am operating on a Mac and using Enthought python I have installed PIP but am having difficulty installing packages.

When I attempt to install Pygame, the package is downloading and begins building but then errors. I realize that Pygame is a relatively complex package but I have similar same problem with simpler packages. Because I thought it may have to do with my installation of Python, I show my env variables at the end. Any help would be appreciated

the trace looks like:

running build_ext

building 'pygame._numericsurfarray' extension

creating build/temp.macosx-10.5-i386-2.7

creating build/temp.macosx-10.5-i386-2.7/src

gcc -fno-strict-aliasing -fno-common -dynamic -arch i386 -DNDEBUG -g -O3 -arch i386 -I/NEED_INC_PATH_FIX -I/Library/Frameworks/Python.framework/Versions/7.3/include/python2.7 -c src/_numericsurfarray.c -o build/temp.macosx-10.5-i386-2.7/src/_numericsurfarray.o

In file included from src/_numericsurfarray.c:23:

src/pygame.h:106:17: error: SDL.h: No such file or directory

In file included from src/_numericsurfarray.c:23:

src/pygame.h:350: error: expected specifier-qualifier-list before ‘SDL_VideoInfo’

src/pygame.h:388: error: expected specifier-qualifier-list before ‘SDL_Surface’

src/_numericsurfarray.c:26:27: error: SDL_byteorder.h: No such file or directory
....
....
...
....
src/_numericsurfarray.c:1097: error: expected declaration specifiers or ‘...’ before ‘SDL_Surface’

error: command 'gcc' failed with exit status 1

Command /Library/Frameworks/Python.framework/Versions/7.3/Resources/Python.app/Contents/MacOS/Python -c "import setuptools;__file__='/var/folders/9m/qcp8h8ss4ng1v8429jvnkkrc0000gn/T/pip-build/pygame/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/9m/qcp8h8ss4ng1v8429jvnkkrc0000gn/T/pip-roxs9O-record/install-record.txt --single-version-externally-managed failed with error code 1 in /var/folders/9m/qcp8h8ss4ng1v8429jvnkkrc0000gn/T/pip-build/pygame
Storing complete log in /Users/jc_macpro/.pip/pip.log

my environment variables are:

TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
SHELL=/bin/bash
TMPDIR=/var/folders/9m/qcp8h8ss4ng1v8429jvnkkrc0000gn/T/
Apple_PubSub_Socket_Render=/tmp/launch-iwuiuZ/Render
TERM_PROGRAM_VERSION=309
TERM_SESSION_ID=FDC661E1-1196-448F-8D69-28AD9D7C496B
USER=jc_macpro
COMMAND_MODE=unix2003
SSH_AUTH_SOCK=/tmp/launch-pH83z9/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0:0
Apple_Ubiquity_Message=/tmp/launch-s4tuBY/Apple_Ubiquity_Message
PATH=/Library/Frameworks/Python.framework/Versions/Current/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
PWD=/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages
LANG=en_US.UTF-8
SHLVL=1
HOME=/Users/jc_macpro
LOGNAME=jc_macpro
SECURITYSESSIONID=186a4
_=/usr/bin/env
OLDPWD=/Library/Frameworks/Python.framework/Versions/Current/bin

I would appreciate any help.

UPDATE: 12/22/12 I have sifted through al of the advice and feedback and appreciate it all very much. All efforts at installing the binaries on Enthought did not work. I did not want o add more complexity with Macports so I decided to blow out my Enthought python and simply work with the official Python 2.7. I am a huge fan of Enthought and it was a great way to provide a stable base from which to work when I started messing around with Python. However, as was pointed out it has some limitations.

With Python 2.7 as my default I reinstalled pip, added basic functionality and was then able to install the binaries necessary for pygame, numpy, matplotlib, and wxPython. So now I functioning and once again dangerous - just now with official Python 2.7!! Thank you all.

回答1:

The problem is that you need SDL to install PyGame. You may also want to install various SDL add-on packages (SDL_ttf for fonts, etc.) as well.

As Martijn Pieters suggests, Pygame comes with a binary installer for Mac. I have no idea whether it will work with Enthought Python, but I'd try that first.

If it fails, SDL also has a binary installer for Mac. Again, I don't know if it will work for you, but I'd try it next.

If that fails, I'd use Homebrew. Homebrew (unlike MacPorts and Fink) is designed to work well with any Python installation you want to use, and with that Python's pip. (See here and here for details.) So, type brew search sdl to get a list of all of the add-on packages, and then brew install sdl sdl_foo sdl_bar etc. to install them.

For your additional problem, that you can't pip install anything because of permissions errors in '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/`, that's an easy one: You don't have permission to write to that directory. There are two ways to fix it:

  1. Use sudo pip install foo instead of pip install foo.
  2. Use sudo chmod -R a+w /Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/ to give yourself write access, so you can pip install foo. (You may need to add a few other directories.)

The second one is very much in the spirit of Homebrew (see the two links above, which go into more detail on how and why to do this), and it works great with python.org packages because many people are using it that way regularly, but I can't guarantee that it's a good idea with Enthought packages, while I can guarantee the first one.



回答2:

You are missing a dependency, SDL.

If you have macports install, use that to install libsdl.

Or better still, download the Pygame binary for Mac; it includes the SDL library in the installer.



标签: python pip