bad interpreter while attempting pip install flask - python

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

Related

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

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.

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?

Error creating virtualenv with Python3

I'm working on Linux Mint 17 and I'm trying to create a new virtualenv with Python3 like this:
python3.6 -m venv env
And this is the error that I get:
Error: Command '['/home/ric/myprojs/django-example-channels/env/bin/python3.6', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
I've googled this error message but haven't managed to find anything too informative.
This is my pip version, in case it make any difference:
pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
I've been using Python2 for some time, but I'm new to Python3. I don't know what I may be missing.
UPDATE 1:
Answering #cezar's question, when I type  which python3 this is what I get:
$ which python3
/usr/bin/python3
UPDATE 2:
Answering #Chłop Z Lasu:
$ virtualenv -p python3.6 env
Running virtualenv with interpreter /usr/bin/python3.6
Using base prefix '/usr'
New python executable in /home/ric/myprojs/django-example-channels/example_channels/env/bin/python3.6
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 2328, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 713, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 925, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 1231, in install_python
shutil.copyfile(executable, py_executable)
File "/usr/lib/python3.6/shutil.py", line 104, in copyfile
raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
The error indicates that virtualenv is trying to make an environment in your python path. therefore, you have to specify your virtualenv destination
virtualenv -p python3.6 /path/to/yourenv
For venv and python3.6 installing venv one can use below to fix the issue
sudo apt install python3.6-venv
You gotta install the venv via code bellow:
sudo apt install python3.6-venv
Expanding on the Answer Above:
The error indicates that virtualenv is trying to make an environment in your python path. therefore, you have to specify your virtualenv destination
Since -p is a flag equivalent to --python, you can also use.
$ virtualenv --python=python3.6 /path/to/yourenv
Or
$ virtualenv -p python3.6 /path/to/yourenv

virtualenv looking in the wrong place for easy_install & other files

Somehow I screwed up my python 2.7 installation on my mac so I tried to reinstall with "brew install python". Now when I try to create a new virtualenv, it throws an error about not finding /bin/easy_install. easy_install is actually in /usr/local/bin/easy_install. If I symlink it to /bin, virtualenv fails with /bin/pip and so on - every file it's looking for is actually in /usr/local/bin not /bin
How can I permanently make virtualenv look in the right place: /usr/local/bin?
$ virtualenv env
New python executable in /Users/myusername/code/lambda/env/bin/python2.7
Also creating executable in /Users/myusername/code/lambda/env/bin/python
Installing setuptools, pip, wheel...
Complete output from command /Users/myusername/c...da/env/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel:
Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Collecting wheel
Installing collected packages: setuptools, pip, wheel
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/basecommand.py", line 211, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/commands/install.py", line 311, in run
root=options.root_path,
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/req/req_set.py", line 646, in install
**kwargs
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/req/req_install.py", line 803, in install
self.move_wheel_files(self.source_dir, root=root)
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/req/req_install.py", line 998, in move_wheel_files
isolated=self.isolated,
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/wheel.py", line 465, in move_wheel_files
generated.extend(maker.make(spec))
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 353, in make
self._make_script(entry, filenames, options=options)
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 257, in _make_script
self._write_script(scriptnames, shebang, script, filenames, ext)
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/scripts.py", line 231, in _write_script
self._fileop.write_binary_file(outname, script_bytes)
File "/usr/local/lib/python2.7/site-packages/virtualenv_support/pip-7.1.2-py2.py3-none-any.whl/pip/_vendor/distlib/util.py", line 388, in write_binary_file
with open(path, 'wb') as f:
IOError: [Errno 13] Permission denied: '/bin/easy_install'
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==13.2.0.dev0', 'console_scripts', 'virtualenv')()
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 699, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 872, in create_environment
install_wheel(to_install, py_executable, search_dirs)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 837, in install_wheel
'PIP_USER': '0'
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 777, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/myusername/c...da/env/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 2
About halfway down that output you can see virtualenv looking for /bin/easy_install
$ ls -al /bin/easy_install
ls: /bin/easy_install: No such file or directory
$ ls -al /usr/local/bin/easy_install
lrwxr-xr-x 1 myusername admin 40 Dec 22 14:21 /usr/local/bin/easy_install -> ../Cellar/python/2.7.11/bin/easy_install
But it should be looking in /usr/local/bin instead because that's the only easy_install I have now and it works:
$ which easy_install
/usr/local/bin/easy_install
$ easy_install
install_dir /usr/local/lib/python2.7/site-packages/
error: No urls, filenames, or requirements specified (see --help)
I've tried to pip uninstall virtualenv then pip install virtualenv but that didn't help - same issue.
Anyone know how to fix this?
Thanks!
====================
EDIT: Solved!
Tried using /usr/local/bin/virtualenv-2.7 and it worked as expected. I moved /usr/local/bin/virtualenv then symlinked /usr/local/bin/virtualenv-2.7 back to /usr/local/bin/virtualenv --- now all appears to be well in the world.
Solved! Tried using /usr/local/bin/virtualenv-2.7 and it worked as expected. I moved /usr/local/bin/virtualenv then symlinked /usr/local/bin/virtualenv-2.7 back to /usr/local/bin/virtualenv --- now all appears to be well in the world.
I compiled my own Python 3, then installed virtualenvwrapper. But after I switched from compiling my own Python to using the deadsnakes PPA I ran into the issue described in the question above.
Seems there's something going on with the #! part of the virtualenv script.
The error I was getting was as follows:
nb#ubuntu-0xA520322HC30H:~/proj/redis-py$ mkvirtualenv --python='/usr/bin/python3' redispytest
bash: /home/nb/.local/bin/virtualenv: /usr/local/bin/python3.6: bad interpreter: No such file or directory
My system Python setup had the following symlinks and Python locations:
nb#ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3
lrwxrwxrwx 1 root root 9 Feb 8 11:43 /usr/bin/python3 -> python3.5
nb#ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3.5
-rwxr-xr-x 2 root root 4464400 Nov 28 08:53 /usr/bin/python3.5
nb#ubuntu-0xA520322HC30H:~/proj/redis-py$ which python3.5
/usr/bin/python3.5
nb#ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3.5
-rwxr-xr-x 2 root root 4464400 Nov 28 08:53 /usr/bin/python3.5
nb#ubuntu-0xA520322HC30H:~/proj/redis-py$ ls -la /usr/bin/python3.6
-rwxr-xr-x 2 root root 4695328 Jan 28 10:49 /usr/bin/python3.6
nb#ubuntu-0xA520322HC30H:~/proj/redis-py$ which virtualenv
/home/nb/.local/bin//virtualenv
And, in /home/nb/.local/bin/¹:
nb#ubuntu-0xA520322HC30H:~/proj/redis-py$ cd ~/.local/bin
nb#ubuntu-0xA520322HC30H:~/.local/bin$ ls
pbr pip2 pip3 virtualenv virtualenvwrapper_lazy.sh
pip pip2.7 pip3.5 virtualenv-clone virtualenvwrapper.sh
I wondered where this mysterious, and completely absent /usr/local/bin/python3.6 was in the code.
So I installed a full-text search tool and looked for it in the ~/.local folder.
nb#ubuntu-0xA520322HC30H:~$ cd .local
nb#ubuntu-0xA520322HC30H:~/.local$ sudo apt-get install --quiet --quiet silversearcher-ag
nb#ubuntu-0xA520322HC30H:~/.local$ ag '/usr/local/bin/python3.6'
bin/virtualenv-clone
1:#!/usr/local/bin/python3.6
bin/pbr
1:#!/usr/local/bin/python3.6
Looks like the static reference to Python's in 2 places.
I now have two options:
I can edit the /usr/local/bin/python3.6 text in there to refer to /usr/bin/python3.6
I can make a symlink from /usr/local/bin/python3.6 -> /usr/bin/python3.6
I went with option 1 for the bin/virtualenv-clone file:
But I also did option 2, just in case this problem exists elsewhere on my system.
nb#ubuntu-0xA520322HC30H:~$ sudo ln -s /usr/bin/python3.6 /usr/local/bin/python3.6
Well, whatever it was, that worked:
nb#ubuntu-0xA520322HC30H:~/.local$ mkvirtualenv --python='/usr/bin/python3' redispytest
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/nb/Envs/redispytest/bin/python3
Also creating executable in /home/nb/Envs/redispytest/bin/python
Installing setuptools, pip, wheel...done.
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/preactivate
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/postactivate
virtualenvwrapper.user_scripts creating /home/nb/Envs/redispytest/bin/get_env_details
(redispytest) nb#ubuntu-0xA520322HC30H:~/.local$
Summary: Find out which interpreter location your virtualenv is trying to use, and make a symlink from that location to your actual Python.
The reason you need to do this is that at least a few virtualenv locations will have a #! line that refers to a specific location, but won't change if you, say, switch from compiling your own Python to using a PPA.
At first I was hesitant to do this, since I prefer to let the package manager handle this sort of thing, and not complicate my paths too much. But there really doesn't seem to be any other way to fix this. I tried uninstalling and reinstalling both virtualenv and virtualenvwrapper, to no avail.
¹Hmmm... there's pbr's in my .local/bin. What's next, my .local/fridge? Damn hipsters.

linking python project with virtualenv

I have an ubuntu server 12 running as a guest in virtualbox on a windows 7 host.
In a shared folder /workspace I have a python project project01. Since virtualbox has issues with creating symlinks in a shared folder I created the virtualenv in my users home directory. /home/user1/venv.
I can activate the virtual environment no problem.
source ~/venv/bin/activate
but when I try to run manage.py, I get an error
~/venv/bin/python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
I'm sure I'm missing a path or something, but I'm not sure exactly what path to add and to where. I tried setting PYTHONPATH in the activate script, but that didn't work. Do I need to add the path to django's core management in the activate script?
I see a bunch of django directories under venv/build
Django
django-appconf
django-celery
django-celery-email
django-celery-transactions
django-debug-toolbar
django-filebrowser
django-grappelli
djangohelpers
django-imagekit
django-pipeline
django-redis
django-sslify
django-storages
django-widget-tweaks
do I need to point in there somewhere?
I'm very much a django and virtualenv noob.
UPDATE
It doesn't look like the packages were installed. So this is another matter entirely.
Thanks for your reply. I have some other issues I need to figure out here.
I was in the virtualenv and ran pip install -r requirements.txt which only had 1 error for postgres, but I'm not using a local postgres server so that's not a huge deal. Unless that error is preventing everything from installing, then it is a huge deal.
when I check site-packages I only see the following:
easy-install.pth
pip-1.2.1-py2.7.egg
setuptools-0.6c11-py2.7.egg
setuptools.pth
and pip freeze shows me:
argparse==1.2.1
wsgiref==0.1.2
the error from pip install is:
Exception information:
Traceback (most recent call last):
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/basecommand.py", line 107, in main
status = self.run(options, args)
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/commands/install.py", line 256, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 1042, in prepare_files
req_to_install.run_egg_info()
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/req.py", line 236, in run_egg_info
command_desc='python setup.py egg_info')
File "venv/local/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg/pip/util.py", line 612, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command python setup.py egg_info failed with error code 1 in venv/build/psycopg2
The error looks as if you do not have Django in the venv python path.
You can confirm that it is part of your venv python install using a couple of ways:
If you used PIP to install you can verify that the package is installed using pip freeze
Also check in lib/python2.7/site-packages/ of the venv there should be a django directory in there. This is the directory that is part of the PYTHONPATH for your venv.
If you cannot find the modules in there of have installed them in a different path. Then you will need to make sure that the path is part of the PYTHONPATH of the venv.

Categories