【发布时间】:2016-11-18 00:28:02
【问题描述】:
我看到过类似的问题,但没有一个可以回答我的问题。我最近在 Mac OS X 上使用 Macports 升级到了 python v3.5。如果有一个有效的 Macport,安装 python 包就可以了:
sudo port install py35-numpy
但是,如果我尝试使用 pip3 安装需要 .so 文件的 python 包,则会出现错误。例如,没有 pystan 的端口。首先,我安装 pip
sudo port install py35-pip
然后我使用 pip 将 pystan 安装到我的 Python 3.5 目录
sudo pip3 install --target=/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ pystan
Installing collected packages: Cython, numpy, pystan
Successfully installed Cython-0.24 numpy-1.11.1 pystan-2.9.0.0
并不是说它实际上没有安装 Cython 或 numpy,因为它们已经在那里了。但是当我尝试运行 pystan 时:
Nate$ ipython
Python 3.5.2 (default, Jun 27 2016, 03:10:38)
Type "copyright", "credits" or "license" for more information.
IPython 5.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import pystan
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-7b354c723dbb> in <module>()
----> 1 import pystan
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pystan/__init__.py in <module>()
7 import logging
8
----> 9 from pystan.api import stanc, stan
10 from pystan.misc import read_rdump, stan_rdump
11 from pystan.model import StanModel
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pystan/api.py in <module>()
10 import hashlib
11
---> 12 import pystan._api # stanc wrapper
13 from pystan._compat import string_types
14 from pystan.model import StanModel
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pystan/_api.so, 2): Symbol not found: _PyBaseString_Type
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pystan/_api.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pystan/_api.so
我在尝试通过 pip 安装 numpy 时看到了同样的错误,而使用 netCDF4 时也遇到了同样的错误。
In [2]: import netCDF4
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-f731da2de255> in <module>()
----> 1 import netCDF4
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/netCDF4/__init__.py in <module>()
1 # init for netCDF4. package
2 # Docstring comes from extension module _netCDF4.
----> 3 from ._netCDF4 import *
4 # Need explicit imports for names beginning with underscores
5 from ._netCDF4 import __doc__, __pdoc__
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/netCDF4/_netCDF4.so, 2): Symbol not found: _PyCObject_Type
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/netCDF4/_netCDF4.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/netCDF4/_netCDF4.so
.so 文件有什么问题?或者,就此而言,我的电脑?
【问题讨论】:
-
您是否尝试在没有
--target选项的情况下调用pip3 install?我希望只要您使用 MacPorts 安装的pip3,它就会在正确的位置安装东西。我想知道使用--target运行它是否会产生一些意想不到的子目录或其他东西。 -
@jb326,你可能是对的。请参阅下面的答案。
标签: python macos macports python-3.5