Creating a virtualenv using Python 3 error - python-3.x

I have python in ConEMu loaded and am trying to creating a virtual environment to work in.
I used
pip3 install virtualenv --user
and it said that virtualenv was usccessfully installed, however then I try to
virtualenv .venv
and i get the error message
bash: virtualenv: command not found
wondering if anyone else has run into this problem

virtualenv is built into python 3, and called venv. You don't need to install anything with pip.
You can make a virtualenv in python 3 like this:
python3 -m venv ve

Related

Python3 virtualenv installs python2

I am not sure what is wrong but I can't seem to get python3 in a virtualenv environment. I tried upgrading my ubuntu and updating all the packages - but no luck:
python3 -m virtualenv ENV
Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/ramin/projects/buybulkamerica/ENV/bin/python2
Also creating executable in /home/ramin/projects/buybulkamerica/ENV/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
What can I do to ensure that virtualenv installs python3 instead of python2?
First, uninstall existing virtualenv.
sudo apt-get remove --purge python-virtualenv if you installed it using a package manager.
pip uninstall virtualenv if you have installed it using pip.
pip3 uninstall virtualenv if you have installed it using pip3.
Any one of the above commands will work.
Now install virtualenv again. Since you want python3, you need to run the following command.
pip3 install virtualenv
That should do the trick. Now when you create a new virtualenv, it will use python3.
There may be a better way but I had the same problem and after not finding any solution I tried this and it worked.
After you have installed virtualenv using pip, it doesn't matter if you used pip or pip3 if you give the location of your python3 installation to the virtualenv command, like this.
Create new virtualenv
virtualenv --python=/usr/bin/python3.6 environmentname
Access virtualenv
source /environmentname/bin/activate
If this doesn't work, use complete path from pwd
source /complete/path/to/environmentname/bin/activate
Stop virtualenv
deactivate

How to get virtualenv to run Python 3 instead of Python 2.7?

On Mac, if I simply open a new terminal window and run:
python --version
I get:
3.6
but if I do this:
virtualenv venv && source venv/bin/activate
and then, in that environment, I run :
python --version
I get:
2.7
I need virtualenv to run 3.6. How do I do that?
This :
/usr/bin/python
is 2.7 but this:
/usr/local/bin/python
is 3.6. The path for my normal user has /usr/local/bin come up before /usr/bin/. Is virtualenv running as someone else? How do I control its path?
I ran this:
virtualenv -p /usr/local//Cellar/python/3.6.5/bin/python3 venv
but then I do this:
virtualenv venv && source venv/bin/activate
and I'm running in an environment with 2.7.
On Python 3 you don't need virtualenv script anymore, you should just use the venv module included with standard lib:
python3 -m venv myvenv
But if you really want to keep using the old virtualenv script, you can - specify the interpreter explicitly with the -p option:
virtualenv -p /path/to/python3 myvenv
The easiest way is to change python globally to Python3 as I think you're using it more often than Python 2.7 (or hopefully always). To achieve this, add the following line of code at the end of your .bash_profile:
alias python='python3'
virtuanenv is using /usr/bin/python, hence it should work now.
If you don't want to change it globally, than you should use the following command to create your Python3.6 virtual environment:
python3 -m venv venv
or the explicit Python version if you have multiple Python3 versions installed:
python3.6 -m venv venv
On more suggestion at the end: I recommend you to read something about pipenv as it's the new recommended way to handle virtual environments and your whole package management at once. It's super easy and fixes a lot of common issues. Here's a nice article from realpython.com on that topic.
Hope I could help you. Have a nice day.

Error: Creating Virtual Environment (with virtualenv) while setting up python Selenium via Terminal

I'm stuck trying to create a virtual environment. The instructions for this step are:
Create a new VirtualEnv in the directory for your Selenium files:
virtualenv -p /usr/bin/python3.0 venv
After checking my version of python I get: "Python 3.6.0 :: Anaconda 4.3.1 (x86_64)".
I tried replacing '3.0' with '3.6':
Wills-MacBook-Pro-2:my_selenium_project willdudek$ virtualenv -p /usr/bin/python3.6 venv
and get this error message:
The path /usr/bin/python3.6 (from --python=/usr/bin/python3.6) does
not exist
I also tried quitting terminal and reopening (so I'm not in my_selenium_project), importing virtualenv in Python, then trying to create a virtual environment using virtualenv my_selenium_project and that didn't work.
Do I need a different command since I'm running Python through Anaconda?

pip not running with Python 3.5

I have installed Python 3.5 and Pip but When I am type pip or pip3 in console, i get this error
The folder you are executing pip from can no longer be found.
If I run pwd, I get
/home/zahid
Pip was installed using
sudo python /usr/local/lib/python3.5/site-packages/easy_install.py pip
and output that I got was
[sudo] password for zahid:
Searching for pip
Best match: pip 8.1.1
Adding pip 8.1.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip3.5 script to /usr/local/bin
Installing pip3 script to /usr/local/bin
Using /usr/local/lib/python3.5/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
Can anyone tell me what is going on here
which python3 returns
/usr/bin/python3
which pip returns
/usr/local/bin/pip
which pip3 returns
/usr/local/bin/pip3
echo $PYTHONPATH returns
nothing blank
Regards
Please close this terminal and open a new terminal. You may have deleted some files inadvertently. As a result the terminal is unable to locate some links or environment variables. I faced the same issue. In a new terminal everything went fine.
I had this error on my Mac and restarting fixed this problem for me.
Does sudo pip work?
If so, check to make sure your profile isn't messed up. Check your path variable using the echo command with something like echo $PATH
You need to make sure /usr/local/bin is present in your user profile.
If not, did you install pip into 3.5 and are you accidentally running some other version of python like python 2?
Create a symbolic link using
ln -s /usr/local/bin/pip /usr/bin/pip
test it by running
pip -V

Pip won't install into python 3 when using homebrew python?

So I've got a virtualenv I've created using pyvenv-3.3, which I thought set up pip to install things into the virtualenv's path. However, I get the following outputs after I've activated by virtualenv:
$ pip --version
pip 1.4.1 from /usr/local/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg (python 2.7)
pip-3.3 --version
pip 1.4.1 from /usr/local/lib/python3.3/site-packages/pip-1.4.1-py3.3.egg (python 3.3)
This is all fine and good, but then my sys.path is this:
['',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python33.zip',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-darwin',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload',
'/Users/alexgolec/Documents/gutenberg/virtualenv/lib/python3.3/site-packages']
Most notably, the whole site-packages directory is outright missing. Furthermore, this output indicates to me that I'm probably using a python that installed through homebrew at some point. Most infuriatingly, none of the directories in my sys.path are compatible with pip.
Any thoughts on remedies? I won't manually edit my sys.path, but maybe there's some configuration with pip I can do?
Install virtualenvwrapper (makes using virtualenv so much easier):
pip install virtualenvwrapper
.. and then try this:
mkvirtualenv <your_env> -p /usr/local/bin/python3
Where homebrew sticks python is different from where your system has it. You can run the following to see what I'm talking about:
which python
which python3

Resources