1
後導入在Python安裝的軟件包我最近更新了我的系統(OXS 10.9.1 - > 10.9.2),並使用BREW(2.7.3 - > 2.7.6)我的蟒蛇。無法更新OSX和Python
現在我變得很奇怪的行爲。一個例子是試圖運行一個測試應用程序,它會創建燒瓶插座:
[email protected]:~/Workspace/sandbox $ python app.py
Traceback (most recent call last):
File "app.py", line 9, in <module>
import flask, flask_sockets, time, threading, simplejson
File "/usr/local/lib/python2.7/site-packages/flask/__init__.py", line 21, in <module>
from .app import Flask, Request, Response
File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 26, in <module>
from . import json
File "/usr/local/lib/python2.7/site-packages/flask/json.py", line 25, in <module>
from itsdangerous import json as _json
ImportError: No module named itsdangerous
首先想到的是更新itsdangerous:
[email protected]:~/Workspace/sandbox $ pip install itsdangerous --upgrade
Requirement already up-to-date: itsdangerous in /usr/local/lib/python2.7/site-packages
Cleaning up...
檢查是否正確安裝:
[email protected]:~/Workspace/sandbox $ locate itsdangerous
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/PKG-INFO
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/SOURCES.txt
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/dependency_links.txt
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/installed-files.txt
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/not-zip-safe
/usr/local/lib/python2.7/site-packages/itsdangerous-0.23-py2.7.egg-info/top_level.txt
/usr/local/lib/python2.7/site-packages/itsdangerous.py
/usr/local/lib/python2.7/site-packages/itsdangerous.pyc
檢查我PYTHONPATH:
[email protected]:~/Workspace/sandbox $ echo $PYTHONPATH
/usr/local/lib/python2.7/site-packages/
檢查Python是在尋找正確的PYTHONPATH:
[email protected]:~/Workspace/sandbox $ python
Python 2.7.6 (default, Mar 6 2014, 10:46:26)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import itsdangerous
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named itsdangerous
>>> import os
>>> os.getenv("PYTHONPATH")
'/usr/local/lib/python2.7/site-packages/'
>>>
我在與其他基本包類似的問題,如過多的virtualenv:
[email protected]:~/Workspace/sandbox $ virtualenv venv
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2720, in <module>
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 588, in resolve
The `plugin_env` should be an ``Environment`` instance that contains
pkg_resources.DistributionNotFound: virtualenv==1.9.1
是它安裝?
[email protected]:~/Workspace/sandbox $ pip install virtualenv --upgrade
Requirement already up-to-date: virtualenv in /usr/local/lib/python2.7/site-packages
Cleaning up...
但奇怪的是這一次Python可以看出來:
[email protected]:~/Workspace/sandbox $ python
Python 2.7.6 (default, Mar 6 2014, 10:46:26)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import virtualenv
>>> dir(virtualenv)
['ACTIVATE_BAT', 'ACTIVATE_CSH', 'ACTIVATE_FISH', 'ACTIVATE_PS', 'ACTIVATE_SH', 'ACTIVATE_THIS', 'BIG_ENDIAN', 'ConfigOptionParser', 'ConfigParser', 'DEACTIVATE_BAT', 'DISTUTILS_CFG', 'DISTUTILS_INIT', 'FAT_MAGIC', 'LC_LOAD_DYLIB', 'LITTLE_ENDIAN', 'Logger', 'MH_CIGAM', 'MH_CIGAM_64', 'MH_MAGIC', 'MH_MAGIC_64', 'OK_ABS_SCRIPTS', 'REQUIRED_FILES', 'REQUIRED_MODULES', 'SITE_PY', 'UpdatingDefaultsHelpFormatter', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__version__', '_find_file', 'abiflags', 'base64', 'call_subprocess', 'change_prefix', 'codecs', 'convert', 'copy_required_modules', 'copyfile', 'copyfileordir', 'create_bootstrap_script', 'create_environment', 'default_config_file', 'default_storage_dir', 'distutils', 'errno', 'expected_exe', 'file_search_dirs', 'fileview', 'filter_install_output', 'find_wheels', 'fix_lib64', 'fix_local_scheme', 'fixup_egg_link', 'fixup_pth_and_egg_link', 'fixup_pth_file', 'fixup_scripts', 'get_installed_pythons', 'glob', 'install_activate', 'install_distutils', 'install_python', 'install_wheel', 'is_cygwin', 'is_darwin', 'is_executable', 'is_executable_file', 'is_jython', 'is_pypy', 'is_win', 'join', 'logger', 'logging', 'mach_o_change', 'main', 'majver', 'make_environment_relocatable', 'make_exe', 'make_relative_path', 'maxint', 'minver', 'mkdir', 'optparse', 'os', 'path_locations', 'py_version', 're', 'read_data', 'relative_script', 'resolve_interpreter', 'rmtree', 'shutil', 'strtobool', 'struct', 'subprocess', 'subst_path', 'sys', 'tarfile', 'tempfile', 'user_dir', 'virtualenv_version', 'writefile', 'zlib']
>>> virtualenv.is_darwin
True
>>> virtualenv.__file__
'/usr/local/lib/python2.7/site-packages/virtualenv.pyc'
>>>