从python 3中导出python 2中的库

时间:2013-05-08 19:05:16

标签: python python-3.x mapnik

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

例如,我想使用mapnik,所以我刚用homebrew安装它,然后在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

一个想法?

请:)

1 个答案:

答案 0 :(得分:1)

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

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

因此,您应该在调用PATH时更改brew,以便将python3用作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