2014-06-19 47 views
0

在終端運行此命令:Python腳本沒有執行(名爲APNSWrapper無模塊)

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() 

這真是令人沮喪的我,不知道爲什麼腳本不執行。

+0

如果你正在運行在Linux上嘗試'須藤PIP安裝apns' –

+0

運行它的MAC

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 

更多信息 - 小牛隊。乾杯。 – user3754111

+0

不要做sudo pip,永遠:http://opensourcehacker.com/2012/09/16/recommended-way-for-sudo-free-installation-of-python-software-with-virtualenv/ –

回答

0

最有可能的是pippython指向不同的Python安裝。一個可能來自軟件包管理器,一個可能來自系統默認值。

您可以通過執行命令

which python

which pip

大概PIP安裝軟件包對你要使用其他Python安裝發現這一點。

問題的解決方案無論它如何表現出來,都是爲您的Python軟件包安裝使用virtualenv環境。 virtualenv創建一個獨立的文件夾,其中包含python解釋器和軟件包安裝,您可以在出現問題時清除並重建。

首先安裝virtualenv。

然後執行:關於Python和virtualenv中安裝

+0

這是問題 - 安裝了2個版本的python。 – user3754111

相關問題