In the terminal I run this command:
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
I have tried to install the module:
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...
I have tried to install APNS:
Pip install apns
I get the following error:
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('rn', '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('rn', '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
script code:
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()
This is really frustrating me, not sure why the script is not executing.
Advertisement
Answer
Most likely pip
and python
point to different Python installations. One might be from package manager, one might be from the system defaults.
You can find this out by doing commands
which python
which pip
Probably pip installs packages against some other python installation you are trying to use.
The solution to the problem, no matter how it has manifested itself, is to use virtualenv
environments for your Python package installations. virtualenv
creates a self-contained folder containing the python interpreter and package installations, which you can wipe clean and rebuild in the case of problems.
First install virtualenv.
Then do:
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
More information about python and virtualenv installations