How do I install mod_wsgi on Mac (High Sierra)? - python

I'm using Mac 10.13.6 (High Sierra) with this version of Apache ...
localhost:mod_wsgi-4.6.5 davea$ httpd -version
Server version: Apache/2.4.33 (Unix)
Server built: Apr 3 2018 17:54:07
How do I install the mod_wsgi module so that Apache can load my Python site? I tried using pip but got the most baffling permission errors despite the fact I'm using sudo ...
(venv) localhost:tmp davea$ sudo pip install mod_wsgi
The directory '/Users/davea/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/davea/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: mod_wsgi in /Users/davea/Documents/workspace/mainpage_project/venv/lib/python3.7/site-packages (4.6.5)
You are using pip version 19.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv) localhost:tmp davea$
(venv) localhost:tmp davea$ sudo mod_wsgi-express install-module
Traceback (most recent call last):
File "/Users/davea/Documents/workspace/mainpage_project/venv/bin/mod_wsgi-express", line 11, in <module>
load_entry_point('mod-wsgi==4.6.5', 'console_scripts', 'mod_wsgi-express')()
File "/Users/davea/Documents/workspace/mainpage_project/venv/lib/python3.7/site-packages/mod_wsgi/server/__init__.py", line 3570, in main
cmd_install_module(args)
File "/Users/davea/Documents/workspace/mainpage_project/venv/lib/python3.7/site-packages/mod_wsgi/server/__init__.py", line 3508, in cmd_install_module
shutil.copyfile(where(), target)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/shutil.py", line 121, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 1] Operation not permitted: '/usr/libexec/apache2/mod_wsgi-py37.cpython-37m-darwin.so'

The instructions outlined under the link below, work under OSX 10.14 (Mojave):
https://modwsgi.readthedocs.io/en/develop/user-guides/installation-on-macosx.html
Based on your output, it seems you are hitting some permission issues.

Related

Have to run all python scripts with sudo

I got a new Raspberry Pi, installed Ubuntu on it, wrote a python script but when I run the script using python3 script.py it just cant find libraries that I installed using pip3 and give library missing erros.
But if I run the same script using sudo python script.py it runs.
I have given script.py permission using sudo chmod 777 script.py , yet same issue
I even gave folder permissions sudo chown user user /home/someuser/Desktop , yet same problem
Now the bigger problem is when I use basic IDE like Thonny , I cant run using sudo from the IDE itself , so I have to run the script from terminal separately which is such a pain
Here is my file permissions
-rwxrwxrwx 1 someuser someuser 2528 Dec 19 17:57 script.py
Here is my folder permissions
drwxr-xr-x 3 someuser someuser 4096 Dec 19 17:56 Desktop
There is no other user on the system except for the one I created during ubuntu setup
I have mostly installed all libraries using sudo pip3 install
One of the error I am getting while trying to use GPIO library
File "/home/someuser/Desktop/beep.py", line 11, in <module>
GPIO.setup(18, GPIO.OUT)
RuntimeError: Not running on a RPi!
Another error:
File "/usr/lib/python3.8/socket.py", line 231, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
PermissionError: [Errno 1] Operation not permitted
Is there a way where I dont have to use sudo every time and makes life easy and easily work with installed libraries.
Here is some additional info
/usr/lib/python38.zip
/usr/lib/python3.8
/usr/lib/python3.8/lib-dynload
/home/someuser/.local/lib/python3.8/site-packages
/usr/local/lib/python3.8/dist-packages
/usr/lib/python3/dist-packages
someuser#pi4:~$ which python3
/usr/bin/python3
did you use sudo to install libraries, if so you, thats why its not available for your current user.
install packages with pip install --user <package_name> to install them for current user.
or
use a virtualenv

Elastic Beanstlak CLI Installation Error

I downloaded the EBCLI with sudo pip install awsebcli --upgrade --user
When running eb --version I get the following error.
Traceback (most recent call last):
File "/home/andrew/.local/bin/eb", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/local/google-cloud-sdk/platform/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
File "/usr/local/google-cloud-sdk/platform/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/google-cloud-sdk/platform/google_appengine/lib/setuptools-0.6c11/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: awsebcli==3.12.4
Any ideas?
Edit:
Here is my pip --version:
pip 9.0.3 from /usr/local/lib/python2.7/dist-packages (python 2.7)
The problem is that you installed awsebcli as the root user, but performed eb --version as a non-root user. So, as far as the non-root user is concerned, awsebcli never got installed.
To run eb as a non-root user:
pip install awsebcli (without the sudo)
To verify this worked, find awsebcli in the output of pip list
If 1. causes you a problem, I recommend installing the awsebcli after setting up a virtualenv. Basically, virtualenv compartmentalizes your Python packages so you do not mess with the system's version of Python and the root user.

Python Flask not working properly on Bash on Ubuntu on Windows

I am trying to run a flask app on my Windows 10 laptop through Bash on Ubunutu on Windows, but I am getting the following error:
None
Traceback (most recent call last):
File "app.py", line 126, in
app.run(debug=True) #Deubug is set to true
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 841, in run
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 720, in run_simple
s.bind((hostname, port))
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied
I am not trying to run a restricted port. It should be on port 5000.
Here are the commands I ran:
sudo apt-get install python-pip
sudo pip install Flask
sudo pip install flask-bootstrap
sudo pip install bokeh
python app.py
Whenever Flask was installed, I got back a warning:
The directory '/home/User/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/User/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Also, running sudo python app.py does not help either.
Any thoughts on what is happening?

Could not install tweepy, a python library in Ubuntu 16.04 in a remote host allocated by LONI using pip and easy_install

Whenever I try to install tweepy, a python library inside a remote host, it fails, although I have pip and python of appropriate version installed. My python version is anaconda 2.7.13 and pip version is 9.0.1. Thanks in advance!
So, I have tried the following commands below and none of them worked.
pip install tweepy
pip install --user tweepy
It gives the error:
Traceback (most recent call last):
File "/usr/local/packages/python/2.7.10-anaconda/bin/pip", line 6, in <module>
sys.exit(pip.main())
File "/usr/local/packages/python/2.7.10-anaconda/lib/python2.7/site-packages/pip/__init__.py", line 239, in main
ensure_easy_pth()
File "/usr/local/packages/python/2.7.10-anaconda/lib/python2.7/site-packages/pip/__init__.py", line 217, in
ensure_easy_pth
with open(path, 'w') as fo:
IOError: [Errno 13] Permission denied: '/usr/local/packages/python/2.7.10-anaconda/lib/python2.7/site-packages/easy-install.pth'
When I try to use easy_install:
easy_install tweepy
It gives the error:
error: can't create or remove files in install directory
The following error occurred while trying to add or remove files in the installation directory:
[Errno 13] Permission denied: '/usr/local/packages/python/2.7.10-anaconda/lib/python2.7/site-packages/test-easy-install-40557.write-test'
The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:
/usr/local/packages/python/2.7.10-anaconda/lib/python2.7/site-packages/
Perhaps your account does not have write access to this directory? If the installation directory is a system-owned directory, you may need to sign in as the administrator or "root" account. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHONPATH environment variable.
For information on other options, you may wish to consult the
documentation at:
https://setuptools.readthedocs.io/en/latest/easy_install.html
Please make the appropriate changes for your system and try again.

bad interpreter while attempting pip install flask

I do have Flask installed at my root directory, however whenever I change directories and run a virutalenv venv to attempt to install flask via pip install flask I receive the following error
bash: /home/phillipsk/rampup/sql/venv/bin/easy_install: /home/phillipsk/rampup/webapp/sql/venv/bin/python: bad interpreter: No such file or directory
Here are the contents of the venv directory
activate activate.csh activate.fish activate_this.py easy_install easy_install-2.7 pip pip2 pip2.7 python python2 python2.7
I can run /home/phillipsk/rampup/webapp/sql/venv/bin/python
and the python interpreter opens
Python 2.7.6
here is the ls -l of
/home/phillipsk/rampup/webapp/sql/venv/bin/python
-rwxr-xr-x 1 root root 3349512 Aug 15 13:11 /home/phillipsk/rampup/webapp/sql/venv/bin/python
This is my attempt at running pip install flask
> (venv)phillipsk#phillips:~/rampup/webapp/sql/venv/bin$ pip install flask Downloading/unpacking flask Cleaning up... Exception: Traceback
> (most recent call last): File
> "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/basecommand.py",
> line 122, in main
> status = self.run(options, args) File "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/commands/install.py",
> line 278, in run
> requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle) File
> "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/req.py",
> line 1153, in prepare_files
> location = req_to_install.build_location(self.build_dir, not self.is_download) File
> "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/req.py",
> line 218, in build_location
> _make_build_dir(build_dir) File "/home/phillipsk/rampup/webapp/sql/venv/local/lib/python2.7/site-packages/pip/req.py",
> line 1527, in _make_build_dir
> os.makedirs(build_dir) File "/home/phillipsk/rampup/webapp/sql/venv/lib/python2.7/os.py", line
> 157, in makedirs
> mkdir(name, mode) OSError: [Errno 13] Permission denied: '/home/phillipsk/rampup/webapp/sql/venv/build'
>
> Storing debug log for failure in /home/phillipsk/.pip/pip.log
sudo pip install flask does work but regardless after running either pip commands I immediately enter into a python interpreter and import flask with no success
As a temporary solution, try changing ownership of your venv folder and all underlying files and folders:
sudo chown -R yourusername:yourusersgroup venv
then reactivate virtualenv and try instaling flask without sudo.
Btw. if you are using sudo when creating virtualenvs, you shouldn't. Run virtualenv /path/to/virtualenv without sudo and logged in as a regular user, activate it and then pip install stuff. Hope this helps.
As a sidenote look into virtualenvwrapper project. It might make things easier for you in the future.
http://virtualenvwrapper.readthedocs.org/en/latest/
the directory is owned by root,
you said it yourself
-rwxr-xr-x 1 root root 3349512 Aug 15 13:11 /home/phillipsk/rampup/webapp/sql/venv/bin/python
so to do it just
sudo pip install flask

Categories