I'm working on OSX 10.13.3 with Python 2.7 installed. I want to make a virtualenv with Python 3 and Django 2.0. I have made a virtualenv as follows:
virtualenv -p /usr/local/bin/python3 .venv
It says Installing setuptools, pip, wheel...done..
Then I enter the virtualenv with:
source .venv/bin/activate
But when I try pip install Django I get:
-bash: /Users/me/Dropbox (Personal)/Projects/landapp/.venv/bin/pip: "/Users/me/Dropbox: bad interpreter: No such file or directory
I think this might be something to do with having a space in the path?
I need to use Dropbox for both business and personal, and I'd rather not rename the folders, as I suspect it'll cause other problems. Is there any way around this?
Related
I have a Linux machine with Ubuntu rel 20.10, I'm using the robot framework with Eclipse. I have a problem with a Sikulilibrary
doesnt'work. I tried to pip install robotframework-SikuliLibrary,
But i have this error
> Exception : Initializing test library Sikulilibrary with no arguments
> failed:Permission error[Errno13]Permission denied
I tried to install Selenium library all is ok,do you have any questions about this issue?
Robotframework 3.2
Python 3.8.6
Thanks a lot
pip wants to install the package in your system, and you don't have the right to write here. But... Do NOT use sudo with pip. This will install system-wide and can break your installation or a package can overwrite this one.
Use virtualenv, or pipenv.
E.g. To use virtualenv:
cd your-project
python -mvenv .venv
source .venv/bin/activate
# and then
pip install XXX
You will need to call source .venv/bin/activate anytime you want to work and launch your project. The behavior is to change the installation path to a local path (and not your system).
Or, like said #BIOS in https://stackoverflow.com/a/66785567/1472048 comment, use your "home" installation with "--user" option to install in ~/.local/lib.
Make sure that you are adding the module in the correct Python installation (your Python 3.8 and not the system Python) and that you are installing in your home directory. This way no special permission will be needed.
pip3 install --user robotframework-SikuliLibrary
The above will install the package in the user site-packages directory of the current (running) Python. In my case it is ~/.local/lib/Python3.9/site-packages, which is already in my PATH. It should be the case for you too, so you should be good to go.
Otherwise, if you have problems like ModuleNotFoundError just find your site-packages directory with:
python3 -m site
You will have it under USER_SITE. Take note of it and add it to PATH following help from this question.
Otherwise, like #Metal3D said, you could use a virtual environment
I am trying to use virtualenv to create a virtual python environment on my mac. I have downloaded virtualenv however I can't run it because it can't find the path to my installation of python3 even though I am supplying the correct path. Here is the command I have run and the response:
virtualenv --python=/usr/local/bin/python3 newfolder
zsh: /usr/local/bin/virtualenv: bad interpreter: /usr/local/opt/python3/bin/python3.6: no such file or directory
Also I have tried running the command with quotes like so:
virtualenv --python='/usr/local/bin/python3' newfolder
zsh: /usr/local/bin/virtualenv: bad interpreter: /usr/local/opt/python3/bin/python3.6: no such file or directory
Please note I am supplying the correct path to python3 as far as I can tell.
Here is what I get when I run which python3
which python3
/usr/local/bin/python3
Also virtualenv appears to be correctly installed. Here is evidence for this:
pip3 install virtualenv
Requirement already satisfied: virtualenv in /Users/mathewlewis/Library/Python/3.7/lib/python/site-packages (16.7.9)
Also, in case this is relevant, the software I have is currently mac os catalina 10.15.2
Not only would I like a solution (as has been given at this point) I would also like a reason why this didn't work.
Try:
python3 -m venv venv
source ./venv/bin/activate
Your virtualenv script uses bad interpreter /usr/local/opt/python3/bin/python3.6 which you have had installed and later removed. To fix the script reinstall virtualenv package using an existing Python:
pip3 install -U virtualenv
I'm having difficulty getting Django to work on my Mac. I pip installed it, as well as downloading it on PyCharm. I have a feeling it will work on PyCharm if I knew what I'm doing. I dont. haha. It's my first time. I am trying to work off the tutorial that they provide on their site. Here is where I run into trouble.
In terminal I type:
python -m django --version
and I get:
/usr/bin/python: No module named django
but when I type:
pip install Django
I get:
Requirement already satisfied (use --upgrade to upgrade): Django in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
The tutorial wants me to type:
django-admin startproject mysite
and I get this:
-bash: django-admin: command not found
So to my question. What is going on here? I'm thinking my path to it is different than what is expected, though I'm not fully sure. If you know the startproject mysite could you give it to me? Meaning, if you know the folders and content I think I could get it running on PyCharm. My PyCharm says it's been downloaded, so I think this would be a great way to go into it.
Many thanks.
From Comments
Looks like a virtual environment problem. Without going into the extreme details of your environment settings, try the following: make and navigate to an empty directory, type pyvenv-3.5 ./Env, then source ./Env/bin/activate, next pip install django, and finally python -m django --version. This virtual environment should work and be less prone to other odd PATH problems.
Additional Info
You will need to run the command source ./Env/bin/activate when you open up a new shell or run a bash script in order to active this environment.
Also, you can now manage your pip packages (including django) by using pip freeze > ./requirements.txt to create a lists of your packages w/ version numbers and 'pip install -r ./requirements.txt` to install the packages.
Seems to me that pip is not configured with the python that you are using. From the output you posted, pip is installing Django for the python executable residing in here:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
what is the output of ls -l $(which python) ?
This will tell you where the python you are using is. If it's different than the path above, pip is installing packages on another python executable.
You have 2 quick options.
Put a softlink to the python residing in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages inside your /usr/bin/ or wherever is imported before the path that which python shows.
ln -s {target-filename} {symbolic-filename}
which is probably
ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /usr/bin/python
Use a Virtual Environment.
pyenv ./env
source ./env/bin/activate
Now you are working on a virtual environment, which has its own pip and python so you should be fine to do anything you'd want !
Hope it helps
I have python2.6 on ubuntu lucid.I have installed virtualenv 1.8.2 for python2.6 .There is the virtualenv-1.8.2-py2.6.egg in /usr/local/lib/python2.6/dist-packages folder.
I want to install python2.7 using virtualenv so I can test some of my code.How do I go about this?I tried
virtualenv venv27 --distribute --no-site-packages --python=python2.7
which gave an error like
The executable python2.7 (from --python=python2.7) does not exist
Please tell me how to go about this? Do I have to upgrade my O.S ?
virtualenv does not download or install Python (different from Ruby's rvm).
When you specify what python you want virtualenv to be based on (--python=PYTHON_BIN), that executable must exist. virtualenv uses that python installation to create its symlinks, shebangs, and everything.
As #Blender and #Dikei told you, you must have Python 2.7 before you create your virtualenv.
The scenario is: I am on Ubuntu 11 which comes with Python 2.7, I want to run Mozilla JetPack which supports Python 2.5/2.6 and Google App Engine which only supports Python 2.5.
Read that its not a good idea to remove Python 2.7 as Ubuntu maybe using it. So the correct way is to use virtualenv. But I am quite lost using it. I installed Python 2.5 in /usr/local/python25 following this guide
I tried
jiewmeng#JM:/usr/local/python25/bin$ ./python --version
Python 2.5.5
jiewmeng#JM:/usr/local/python25/bin$ ./python virtualenv /works/tmp/test
./python: can't open file 'virtualenv': [Errno 2] No such file or directory
then the below works but I will be using Python 2.7
jiewmeng#JM:/usr/local/python25/bin$ virtualenv /works/tmp/test
New python executable in /works/tmp/test/bin/python
Installing distribute.................................................................................................................................................................................done.
jiewmeng#JM:/usr/local/python25/bin$ cd /works/tmp/test/bin
jiewmeng#JM:/works/tmp/test/bin$ ls
activate activate_this.py easy_install easy_install-2.7 pip python
jiewmeng#JM:/works/tmp/test/bin$ ./python --version
Python 2.7.1+
Also, how do I then run Mozilla JetPack or Google App Engine with this version of Python? Sorry I am new to Python (and Linux/Ubuntu)
Outline:
First cd to /usr/local/python25/bin
Download setuptools for Python2.5 (setuptools-0.6c11-py2.5.egg)
Install it (sh setuptools-0.6c11-py2.5.egg).
Now install pip (easy_install pip).
Install virtualenv and virtualenvwrapper using pip (pip install v... etc.).
Configure WORKON_HOME for virtualenv wrapper to work (export WORKON_HOME = $HOME/.virtualenvs). You can use any other directory you want (not just $HOME/.virtualenvs). Just make sure to use the full path.
Now create a virtualenv (mkvirtualenv foobar).
Switch to the new virtualenv (workon foobar).
Now install GAE, JetPack and whatever you want using pip install blah
Why did your install not work?
Looks like you did not install virtualenv for Python2.5. Hence this will not work.
jiewmeng#JM:/usr/local/python25/bin$ ./python virtualenv /works/tmp/test
You can check by running ls command in that directory. I suspect you won't find virtualenv file there.
However this worked for you.
jiewmeng#JM:/usr/local/python25/bin$ virtualenv /works/tmp/test
Because it is using the virtualenv file for system default Python2.7. You can check which virtualenv and opening the virtualenv script. You'll see that the #! will point to system default python.
So you need to install the easy_install and pip for Python 2.5 before you can create virtualenv for Python 2.5. Just follow the steps outlined above.
You don't need to do anything fancy outside the virtualenv wrapper. Just use the --python=python2.5 flag (check out the man page for virtualenv form more). It does not matter what version you install it with, you just have to select the right executable for python in the virtual environment.
e.g. mkvirtualenv --python=python2.5 --distribute python25 if the python flag fails, either add a symlink (ln -s) to python25 in your $PATH or use the full path name on the python flag.
Also, default for multiple python installations is to have, for all 'altinstall' versions, a separate python and easy_install. So, for example: python2.5 ,easy_install-2.5 ,python2.6, easy_install-2.6 etc.