gpt4 book ai didi

python - 从 python 3 导出 python 2 的库

转载 作者:太空宇宙 更新时间:2023-11-03 18:59:11 24 4
gpt4 key购买 nike

我正在使用 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

一个想法?

请:)

最佳答案

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

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

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

关于python - 从 python 3 导出 python 2 的库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16448301/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com