I'm using python3 v3.10.2 and after creating a virtual environment with :
/usr/bin/python3 -m venv myvenv
it create the following folder content :
activate
activate.csh
activate.fish
Activate.ps1
pip
pip3
pip3.10
python -> python3
python3 -> /usr/bin/python3
python3.10 -> python3
The fact that python points to python3 and override the default python(2) is an issue! (similarly for pip). I couldn't find and option to avoid this behaviour? Did I missed something?
Related
I have a few questions related to Python paths. I used homebrew to install python3 on my Mac:
# homebrew python
> which -a python
python: aliased to /usr/local/bin/python3.9
# system python
❯ which -a python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
/usr/local/bin/python3
/usr/bin/python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
I then set up a virtual environment using the command python -m venv venv. After activating it, I get:
> which -a python
python: aliased to /usr/local/bin/python3.9
/Users/kshitijsachan/Documents/venv/bin/python
> which -a python3
/Users/kshitijsachan/Documents/venv/bin/python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
/usr/local/bin/python3
/usr/bin/python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
My questions are:
Why does homebrew python take precedence over the venv python when I run which -a python with the venv activated?
Why is /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 listed twice under which -a python3?
Is this the canonical setup for venv's with Homebrew python?
This is the error:
[1]: https://i.stack.imgur.com/t7SCc.png
I have already seen and followed all answers in this site. But I am facing same problem😥😥
It is highly recommended to use virtual environment for kivy
Setup terminal and pip
python -m pip install --upgrade pip setuptools virtualenv
Create a virtual environment inside the root directory of your project
python -m virtualenv kivy_venv
kivy_venv\Scripts\activate
source kivy_venv/Scripts/activate
After creating virtual env then install kivy on virtual env
For more details - https://kivy.org/doc/stable/gettingstarted/installation.html#install-pip
so i have installed both python 2.7 and python 3.8 however in the cmd if i type one of these:
pip install
pip --version
it uses the python 2.7 version. I don't think that i can use the packages installed with python 3.
i have tried:
Reinstalling python (2 & 3)
Adding it to my PATH
Changing the directory that it is saved in
Pip3 commands
bootstraping pip
yet none have worked.(also im on windows 7, and require the pip and python for both 2.7 & 3.8)
when i use:
python3 -m pip install x
or
py -3 -m pip install x
it comes up with:
DLL load failed while importing pyexpat: the specified module could
not be found
Python 3 command in Windows is python3. So if you want to run pip with python 3 you have to do python3 -m pip install.
You can also replace Python 2 path in your Path variable to your Python 3 path, like so when you'll run python command it will use Python 3 directly.
Hope i got useful.
Have a look at the official document,
https://docs.python.org/3/installing/index.html?highlight=pip#work-with-multiple-versions-of-python-installed-in-parallel
if you are on windows you can use,
py -2 -m pip install SomePackage # default Python 2
py -2.7 -m pip install SomePackage # specifically Python 2.7
py -3 -m pip install SomePackage # default Python 3
py -3.4 -m pip install SomePackage # specifically Python 3.4
On Linux, Mac OS X, and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip:
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4
hope this helps!
If you install both versions of python then by simply entering pip command will run that python pip whose path comes first. You could use pip3 for pip corresponding to python3 and pip2 for pip corresponding to python2. But the recommended way is to do following:
For Python 3
py -3 -m pip install
For Python 2
py -2 -m pip install
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
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.