Python脚本没有执行(没有名为APNSWrapper的模块)

时间:2014-06-19 10:02:05

标签: python

在终端中我运行此命令:

Python pnot.py

I get the following error:

Traceback (most recent call last):
  File "pnot.py", line 1, in <module>
    from APNSWrapper import *
ImportError: No module named APNSWrapper

我尝试安装模块:

pip install APNSWrapper==0.6.1

Requirement already satisfied (use --upgrade to upgrade): APNSWrapper==0.6.1 in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Requirement already satisfied (use --upgrade to upgrade): docutils>=0.3 in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages (from APNSWrapper==0.6.1)
Cleaning up...

我曾尝试安装APNS:

Pip install apns 

我收到以下错误:

Downloading/unpacking apns
  Downloading apns-1.1.2.tar.gz
  Running setup.py egg_info for package apns

Installing collected packages: apns
  Running setup.py install for apns
    error: /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/__pycache__/apns.cpython-33.pyc: Permission denied
    Complete output from command /Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3 -c "import setuptools;__file__='/private/var/folders/8g/6w73vzqs04b6f1cq8m8pyswc0000gn/T/pip_build_samiesyed/apns/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/8g/6w73vzqs04b6f1cq8m8pyswc0000gn/T/pip-3yfn_n-record/install-record.txt --single-version-externally-managed:
    running install

running build

running build_py

creating build

creating build/lib

copying apns.py -> build/lib

running install_lib

copying build/lib/apns.py -> /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages

byte-compiling /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/apns.py to apns.cpython-33.pyc

error: /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/__pycache__/apns.cpython-33.pyc: Permission denied

----------------------------------------
Cleaning up...
Command /Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3 -c "import setuptools;__file__='/private/var/folders/8g/6w73vzqs04b6f1cq8m8pyswc0000gn/T/pip_build_samiesyed/apns/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/8g/6w73vzqs04b6f1cq8m8pyswc0000gn/T/pip-3yfn_n-record/install-record.txt --single-version-externally-managed failed with error code 1 in /private/var/folders/8g/6w73vzqs04b6f1cq8m8pyswc0000gn/T/pip_build_s/apns
Storing complete log in /Users/s/.pip/pip.log

脚本代码:

from APNSWrapper import *

wrapper = APNSNotificationWrapper('cert.pem', True)
for token in ['xxxxxxx']:
    token = binascii.unhexlify(token)
    apn = APNSNotification()
    apn.token(token)
    alert = APNSAlert()
    alert.body('hello world')
    apn.alert(alert)
    apn.sound()
    wrapper.append(apn)
wrapper.notify()

这真让我感到沮丧,不知道为什么脚本没有执行。

1 个答案:

答案 0 :(得分:0)

最有可能pippython指向不同的Python安装。一个可能来自包管理器,一个可能来自系统默认值。

您可以通过执行命令

找到它

which python

which pip

可能pip会安装你想要使用的其他python安装包。

问题的解决方案,无论它如何表现出来,都是为您的Python包安装使用virtualenv环境。 virtualenv创建一个包含python解释器和包安装的自包含文件夹,您可以在出现问题时擦除并重建。

首先安装virtualenv。

然后做:

 virtualenv venv   # Create virtualenv installation in folder called venv
 source venv/bin/activate  # Modify your shell and PATH to use python from venv/bin/python
 pip install apns  # Installs apns in venv/lib
 python pnot.py   # Now it runs your script using venv/bin/python interpreter 
 # and packages installed in venv/lib/python2.7

有关python和virtualenv安装的更多信息