1

我正在使用 python 3。我的问题是每次我安装一个包时,它都会为 python2 安装它。

例如,我想使用mapnik,所以我刚刚用自制软件安装了它,然后它在mapnik lib中为python2.7创建了一个文件夹。所以当我使用 Python2.7 而不是 python3 时它可以工作,因为它找不到模块 mapnik。

如何将它添加到 python 3 ?python3 路径:/Users/gabrielgautron/documents/python3

在 mapnik 的安装结束时,我有以下内容:

For non-homebrew Python, you need to amend your PYTHONPATH like so:
  export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH 

所以我在终端中启动这个命令,然后:

MacBook-Pro-de-Gabriel-Gautron:local gabrielgautron$ python3
Python 3.2.4 (v3.2.4:1e10bdeabe3d, Apr  6 2013, 11:25:28) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mapnik
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/mapnik/__init__.py", line 69, in <module>
    from _mapnik import *
ImportError: No module named _mapnik

一个想法?

请 :)

4

1 回答 1

1

查看brew recipe,它取决于您运行时可访问的 python 版本brew

def which_python
  "python" + `python -c 'import sys;print(sys.version[:3])'`.strip
end

因此,鉴于此,您应该PATH在调用时更改您的,brew以便您使用python3as python。例如:

# Figure out the path to python3
PY3DIR=`dirname $(which python3)`
# And /then/ install with brew. That will have it use python3 to get its path
PATH=$PY3DIR:$PATH brew install mapnik
于 2013-05-08T20:01:38.637 回答