Virtualenv: Sourcing bin/activate does not work; no feedback given - python

Been wrestling with this for a couple of hours. I installed virtualenv using easy_install. Then I did a
virtualenv --no-site-packages django
When I execute:
source django/bin/activate
I get a new line prompt with absolutely no feedback
rtaibah#rtaibah-Ubuntu ~ $
My console does not indicate that I am in a virtual environment. I confirmed this by running
easy_install django
And I get permission errors, which is not supposed to happen.I am running Ubuntu

Maybe source bin/activate or . bin/activate

Source with source instead of virtualenv
source django/bin/activate
You should see something like
(django)rtaibah#rtaibah-Ubuntu ~ $

Related

mkvirtualenv running without error but not creating the environment in zsh

I'm transitioning to zsh on my Mac (Catalina). So far so good except my virtualenv and virtualenvwrapper aren't working as expected. I've tried re installation with the following steps:
rm -rf ~/.virtualenvs # Delete all existing data.
pip uninstall virtualenv virtualenvwrapper # Remove
pip install virtualenv virtualenvwrapper # Reinstall
Added following lines to ~/.zshrc
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
export WORKON_HOME="${HOME}/.virtualenvs"
source `which virtualenvwrapper.sh`
I now have access to the commands in zsh. but if I try to make an env with:
mkvirtualenv testenv
I get:
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/alesirowland/.virtualenvs/bin/python3.7
Not overwriting existing python script /Users/alesirowland/.virtualenvs/bin/python (you must use /Users/alesirowland/.virtualenvs/bin/python3.7)
Installing setuptools, pip, wheel...
done.
running lsvirtualenv returns no environments. It also appears to be trying to use 3.7 despite my environment variables written to default to python2.7. Going back into my bash console creates the env but also defaults to python3. What have I got wrong?
EDITs:
verbose output is generally asking to install in ~/.virtualenvs/bin rather than ~/.virtualenvs//bin
workon on an existing env just echos all of my envs to the screen.
Solution found! this line in my .zshrc is affecting virtualenvwrapper for some reason setopt KSHARRAYS

issues with python virtual environment

I am facing following 2 issues:
python command is not using the virtualenvwrapper python.
After activating my virtual environment if I type python then the code still uses the native python libraries. I can easily install libraries etc with pip to my virtual environment but I cannot run any command using python.
e.g. if I execute $ ./manage.py runserverthen it is fine and I can run a django server
but if I try $ python manage.py runserver
or even just
$ python
then it uses the native python libraries and that should not happen
This is while using iterm or terminal in osx. I have never faced this problem in any linux based os
While using any os (linux based or osx), the workon command doesn't work inside any shell script, while it works normally in a terminal
os: osx
sounds like Python might be using the packages in site-packages, which means you should use the --no-site-packages flag when creating your virtualenv (although it seems like this is the default in the current version of virtualenv).
In order to access the virtualenvwrapper functions from a shell script, you will first need to source it: $ source /usr/local/bin/virtualenvwrapper.sh (the path might be different in your case).
You could try install virtualenv and virtualenvwrapper from pip3.
pip3 install virtualenv virtualenvwrapper
And then find where virtualenvwrapper.sh file is:
find / -name 'virualenvwrapper.sh'
I have mine in /usr/local/bin/virtualenvwrapper.sh. But it seems that you have it in some different directory. So you must change below config to fit your needs.
And then in your .bashrc or .zshrc:
# Python3 virtualenv/venvwrapper
export WORKON_HOME=~/.virtualenvs
VIRTUALENVWRAPPER_PYTHON='/usr/bin/python3' # This needs to be placed before the virtualenvwrapper command
export PROJECT_HOME=$HOME/Projects
source /usr/local/bin/virtualenvwrapper.sh # your path to virtualenvwrapper.sh
Let me know if it works :)

virtualenv not pointing to local executables

I've noticed strange behavior of virtualenv installed on my local machine. This is what I've been doing:
tomasz#laptop:~/Development/Python$ virtualenv nac-env
New python executable in nac-env/bin/python
Installing Setuptools...................................................................................................................................................................................................................................done.
Installing Pip.....................................................................................................................................................................................................................................................................................................................................done.
tomasz#laptop:~/Development/Python$ cd nac-env
tomasz#laptop:~/Development/Python/nac-env$ source ./bin/activate
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ which python
/usr/bin/python
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ which pip
/usr/bin/pip
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ which easy_install
/usr/local/bin/easy_install
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ echo $PYTHONPATH
/usr/lib/python2.7/site-packages:/usr/lib/python2.7/dist-packages
(nac-env)tomasz#laptop:~/Development/Python/nac-env$ deactivate
tomasz#laptop:~/Development/Python/nac-env$
As the nettuts screencast says (http://www.youtube.com/watch?v=IX-v6yvGYFg, 6:55), python, pip and easy_install executables should point to files inside the virtual environment and not to /usr/bin/... stuff. If the $PYTHONPATH sysvar is set incorrectly, I think that my installation doesn't work as expected... Does anyone know what's going wrong?
PS I have installed virtualenv globally on my local machine some time ago. Probably it was intalled through pip or sth like that.
Well, I made myself sure this behavior I had in fact is not normal. I've uninstalled existing virtualenv and re-installed it from pip and now everything works perfectly:
tomasz#laptop:~/Development/Python/foo$ source bin/activate
(foo)tomasz#laptop:~/Development/Python/foo$ which python
/home/tomasz/Development/Python/foo/bin/python
(foo)tomasz#laptop:~/Development/Python/foo$ which pip
/home/tomasz/Development/Python/foo/bin/pip
(foo)tomasz#laptop:~/Development/Python/foo$ which easy_install
/home/tomasz/Development/Python/foo/bin/easy_install
(foo)tomasz#laptop:~/Development/Python/foo$ echo $PYTHONPATH
/usr/lib/python2.7/site-packages:/usr/lib/python2.7/dist-packages
I had this happen to me. Did you change your project path?
When I first created the virtual environment, I used ~/src/my_project/venv but later changed it to ~/projects/my_project/venv. When I ran the activate scripts, it was using the old path. To fix this, I did a substitution on all of the scripts in the activate directory with the new path and python, pip, etc. were now sourced from the virtual environment.

Python setup : command not found

Apologies if this is a basic question:
I have been trying to setup Python on my laptop by following the tutorial here. Under PIP, VIRTUALENV + VIRTUALENVWRAPPER subtitle, it says
And now setup virtualenvwrapper:
1 $ export WORKON_HOME=$HOME/.virtualenvs
2 $ export MSYS_HOME=/c/msys/1.0
3 $ source /usr/local/bin/virtualenvwrapper.sh
The last line of above gives me the following error:
$ source /usr/local/bin/virtualenvwrapper.sh
sh.exe": /usr/local/bin/virtualenvwrapper.sh: No such file or directory
So when I test my setup I get the following error:
$ mkvirtualenv TestEnv
sh.exe": mkvirtualenv: command not found
Could some1 help me out please?
THis is all on a Win7 laptop.
Thanks.
From what you wrote it looks to me that you are mixing Windows and Linux shell commands.
I strongly advocate you get the virtualenv working first before you turn to a wrapper
To get virtualenv on Windows 7
pip install virtualenv
then
virtualenv name_to_your_env
name_to_your_env\Scripts\activate
I was having this same problem but got it to work a different way in Windows.
pip install virtualenv
virtualenv venv
.\venv\Scripts\activate.bat
The key here is running activate.bat rather than just activate. Once I did this and closed and opened cmd again and tried the normal
.\venv\Scripts\activate
it worked. I don't know why but it worked for me, hopefully it helps somebody else.
According to your comment, virtualenvwrapper.sh is not in /usr/local/bin.
You should pass correct path to source command.
source /path/to/..../Scripts/virtualenvwrapper.sh
I had encountered with the same problem and solved it by downloading mktemp binary for windows and uncompressing it under git/bin. Then it works. (I was trying to run leiningen [lein help] command under Git Bash, on Windows 7)
This is the download site i visited.

Activated VENV still use system pip and system python? What's wrong?

When I activate a venv, which pip returns /usr/local/bin/pip instead of path/to/my/apps/venv/bin/pop. Why is that?
I am inclined to just rm- rf the pip in /usr/local/bin/pip and install again, but since this is a production server I prefer not to guess too much :-)
My concern is that I have (in usr/local/bin):
easy_install
easy_install-2.6
pip
pip-2.6
virtualenv
virtualenv-2.6
python --version returns 2.6.6 and which python returns /usr/bin/python even though venvis activated?
Running Debian Squeeze
Check your virtualenv for a local directory. If venv/local exists, does it contain pip and easy_install? If it does, you can try working around this problem by editing venv/bin/activate and prepending venv/local/bin to your path just like venv/bin is being prepended.
Something like:
_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/bin:$PATH"
PATH="$VIRTUAL_ENV/local/bin:$PATH" # my new line
export PATH
I'm having a problem similar to what I've described, and unfortunately I have not run it to ground yet. See also: Why do distribute and pip install to my virtualenv's ./local/bin?
What shell are you using? What specific command did you use to activate the virtualenv?
In my case (also using squeeze) I am using bash and it if I run "source bin/activate" then everything in my path (pip, python, etc) is correct.

Categories