在Xcode中安装python3和beautifulsoup编码到Mac

时间:2016-07-07 08:36:24

标签: python xcode macos python-3.x beautifulsoup

我从https://stringpiggy.hpd.io/mac-osx-python3-dual-install/跟踪了这个网址并检查了python版本。

Python --version
>> Python 3.5.2

which python3
>> /Library/Frameworks/Python.framework/Versions/3.5/bin/python3

echo $PATH
>> /Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/local/Cellar/python3/3.5.2/bin:/usr/bin:/bin:/usr/sbin:/sbin

我使用xcode编译我的代码,当我导入urllib并返回时,

Traceback (most recent call last):
  File "python.py", line 21, in <module>
    import urllib.request
ImportError: No module named request
Program ended with exit code: 1

所以我认为python IDE直接用于机器默认的python     并尝试python --version     Python 2.7.10     如何使用Python3安装beautifulsoup 4.x

enter image description here

enter image description here

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

您已将脚本命名为 python.py ,这就是您看到错误的原因:

padraic@home:~$ touch python.py
padraic@home:~$ echo "import urllib.request" > python.py 
padraic@home:~$ cat python.py 
import urllib.request
padraic@home:~$ python python.py 
Traceback (most recent call last):
  File "python.py", line 1, in <module>
    import urllib.request
ImportError: No module named request

重命名文件并删除目录中的所有.pyc文件。