I am a bit confused I want to install pyenv that works with venv. Do I first install pyenv https://github.com/pyenv/pyenv-installer then install https://github.com/pyenv/pyenv-virtualenv or just
install the second one?
Yes, virtualenv is plugin. First install Pyenv, then install virtualenv by cloning the git repo into the plugins folder, using:
$ git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
If you're still confused just follow the directions here:
Installation
Related
I have Anaconda3 installed on my Windows 10 computer. I want to install the pysystemtrade package from GitHub. This is the instructions from the author
"This package isn't hosted on pip. So to get the code the easiest way is to use git:
git clone https://github.com/robcarver17/pysystemtrade.git
python3 setup.py develop"
The question is, where do I clone the project to and where do I run setup.py to get it installed in the correct place in Anaconda3 so I can include the files in my python project?
Thanks,
Dana
Create a conda environment with the python version, switch to that environment to keep track of dependencies for that environment. Then clone the Git repo. Afterwards, install the requirements.txt for that Github project, and run the command he gave you to add that dependency to your conda environment.
conda create -n trade-test python=3.8
conda activate trade-test
git clone https://github.com/robcarver17/pysystemtrade.git
cd pysystemtrade/
pip3 install -r requirements.txt
python3 setup.py develop
I was creating a new virtual environment on Ubuntu 20.04:
$ virtualenv my_env
But it gave an error:
ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data'
Other info:
$ virtualenv --version
virtualenv 20.0.17 from /usr/lib/python3/dist-packages/virtualenv/__init__.py
#yushulx
I also ran into the same issue. I installed both via pip3 and via sudo apt install python3-virtualenv and it gave me an error but after I ran pip3 uninstall virtualenv I could create a virtualenv without issue
Try to create the virtual environment using directly venv module
python3 -m venv my_env
To fix this on Ubuntu 20.04, I had to uninstall virtualenv from the system: apt remove python3-virtualenv, and reinstall it using pip: pip install --user virtualenv --force-reinstall. I had errors about dependencies conflicts, I fixed them by calling pip install --user ${package} --force-reinstall for every package involved.
virtualenv is installed by default with python itself and when you install virtualenv via pip3 and try to create virtual environment using pipenv you will get this error:
ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data
check the version of installed virtualenv using apt list --installed
mine is:
python3-virtualenv/focal,focal,now 20.0.17-1 all [installed,automatic]
with the installed virtualenv by pip3
min is :
virtualenv 20.4.0
default installation of virtualenv is different with pip3 installed virtualenv
so when you try to create a virtual environment using pipenv for example installing django in a directory home/user/djano with pipenv install django~=3.1.5 you will get that error
the solution is remove installed virtualenv using pip3 uninstall virtualenv and use the default installation of virtualenv this time when you create virtual environment with pipenv it will create it successfully.
I want to have virtualenvwrapper. On Debian 10 testing I did:
apt remove python3-virtualenvwrapper # not purge, I want no changes in ~/.virtualenvs/
apt purge python3-virtualenv
/usr/bin/python3.8 -m pip install --force-reinstall virtualenvwrapper
/usr/bin/python3.8 -m pip install --force-reinstall virtualenv==20.0.23
.24 no longer works. I hope it will be solved sometimes...
EDIT 2021.01: I have changed my stack to: pyenv + pyenv-virtualenvwrapper + poetry. Ie. I use no apt or pip installation of virtualenv or virtualenvwrapper, and instead I install pyenv's plugin pyenv-virtualenvwrapper. This is easier way.
If someone encounters this problem inside existing env (when for example using pyenv) you can also use command below (found on GitHub when tried to fix poetry virtual env installation):
pip install --force-reinstall virtualenv
When I installed virtualenv via pip3, it failed to run virtualenv command. Then I changed the installation via:
sudo apt install python3-virtualenv
The virtualenv command can normally work.
I too had this issue. What I found is it is a permissions issue. For some unknown reason ownership of my home directory was off. I did a chown -R for the directory I was using for my project making myself the owner of my own directory and now everything works as normal.
I also had same issue, seems installed version has different user level so I followed their doc and below one work for me:
python3 -m virtualenv --help
To create new environment:
python3 -m virtualenv my_env
I also faced the same issue but after removing virtualenv which was installed with pip3, I could get rid of this error. Uninstall virtualenv with below command (don't forget to use sudo)
sudo pip3 uninstall virtualenv
After this, virtualenv command works totally fine.
It means that there are two virtualenv in your system.
One is "pip install" by sudo or root, the other may be installed by apt(if you are using ubuntu os)
Just uninstall one of them and the error should be fixed.
I fixed this error by removing all virtualenv and virtualenvwrapper related packages on system and reinstall the virtualenv and virtualenvwrapper with pip with below command(as i use ubuntu, so below only show apt)
remove all packages shown in below result
apt list --installed | grep virtualenvwrapper
apt list --installed | grep virtualenvwrapper
install virtualenv virtualenvwrapper with pip
pip install virtualenvwrapper virtualenvwrapper
set ~/.zshrc
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/amd
export VIRTUALENVWRAPPER_SCRIPT=/home/robot/.local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
source /home/robot/.local/bin/virtualenvwrapper.sh
When we use pip3 or python3 to install virtualenv then I got that error too. I had to run each time to create virtualenv (my_env is virtual environment name)
python3 -m virtualenv my_env
But if I install it using
sudo apt install virtualenv
Then virtualenv command works fine.
virtualenv my_env
I have installed virtualenv and virtualenvwrapper on Ubuntu 16.04
I have created one enviroment named env1
$ sudo apt-get install python-pip
$ pip install virtualenv
$ pip install --upgrade pip
$ pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
$ mkvirtualenv env1
Once in (env1) I have installed several packages
(env1) $ pip install numpy
(env1) $ pip install scipy
(env1) $ pip install matplotlib
(env1) $ apt-get install python-tk
I have also installed opencv3 (I am not copying how because is too long)
I am using env1 for a specific project.
Now I want to start another project using the same packages, but I also want to add other packages.
I have created env2, and I was wondering if it is possible to copy env1 to env2 without the need to re-install everything again from scratch.
Your best option is to do this:
virtualenv-1:
pip freeze > requirements.txt
virtualenv-2:
pip install -r requirements.txt
Assuming they are both the on the same system and use the same Python, it is somewhat possible to just copy the site-packages:
cp -Rp /environments/virtualenv-1/lib/python2.7/site-packages \
/environments/virtualenv-2/lib/python2.7/site-packages
This won't necessarily work though:
some packages will install dependencies and other things into /bin/ or elsewhere. most don't, but many do.
if the python versions for the virtualenvs differ -- even on a minor version -- that can break libraries that use c extensions.
So your best bet is to pip freeze and reinstall from that file.
pip install virtualenvwrapper and use the cpvirtualenv command
cpvirtualenv ENVNAME [TARGETENVNAME]
http://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html#cpvirtualenv
Remember to heed the warning
Copying virtual environments is not well supported. Each virtualenv has
path information hard-coded into it, and there may be cases where the copy
code does not know to update a particular file. Use with caution.
I have installed python-django in a ubuntu 14.04, unfortunately I need to use exactly that distribution, but it is unsupported now, to update django I used the pip, how do I use the newer version instead of the apt version?
You need virtualenv. It enables you to create a virtual python environment with its own packages (instead of system-wide packages).
First, install python-virtualenv package with apt-get:
$ sudo apt-get install python-virtualenv # or python3-virtualenv if you use python 3
And create a virtualenv:
$ virtualenv /home/user/venv
Then activate the virtualenv you created (after doing this, you will be using only the packages you installed in this virtualenv, ignoring the system-wide packages):
$ source /home/user/venv/bin/activate
Now you can install the packages you want:
$ pip install django==1.7 # replace 1.7 with the version you need
or if you want to install the latest version currently available (be careful here, in future you can install latest version and the version can be different from the version you worked on)
$ pip install django
After this point, whenever you run python manage.py runserver in a django project, you will be using the django package you installed in this virtualenv.
Extra notes:
You can save the packages you installed, in order to be able to install them again on another virtualenv:
$ pip freeze > requirements.txt
And then you can install the list of packages you saved later with:
$ pip install -r requirements.txt
I have a CentOS 6.4 which the default python version is 2.6.
I want to run a virtualenv at python 2.7, so first I try to install python 2.7.
yum install python27
Then I run
virtualenv -p /usr/bin/python2.7 ./venv
Then the output shows that it try to get setuptools from pypi, but my environment can not reach pypi.python.org. I have update the ~/.pip/pip.conf to use a available local source but the virtualenv still get pip from the pypi.python.org. This is one of the things I get confused.
I check the /usr/lib/python2.7/, the site-packages is empty while /usr/lib/python2.6/ is not. So When I use python 2.7, it has nothing available. When I use the default python, it has pip tools installed, it does not need to get it from pypi.python.org.
How can I install pip for python 2.7 individually?
Previous I install pip by
yum install python-setuptools
yum install python-pip
The second question, how to install pip for python2.7 individually can be solved as the following:
Download python source code of the specific version and install it at /usr/local
wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
Then install setuptools and pip
Install easy_install (prepare ez_setup.py beforehand)
python2.7 ez_setup.py
Install pip
easy_install-2.7 pip
easy_intall-2.7 pip need to visit the internet, in my environment I get the pip source file and use "python2.7 setup.py install".
pip2.7 install [packagename]
In my environment I update .pip/pip.conf to use an internal pip source.
(code above take python 2.7 as an example)
To see the details you can check the following url:
http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
The first question, when creating a new virtual environment, virtualenv will install setuptools for this environment. If python version is not assigned, it use the system default python and default pip. If pip is not find, then try to get it from pypi.python.org.
In my environment, after python2.7 and pip2.7 installed, when trying to create a new virtualenv, it still get pip from pypi.python.org, I guess that virtualenv does not find the relation between python2.7 and pip2.7.
If you can visit pypi.python.org, that is fine.
If you are at an internal environment that can not visit pypi.python.org, virtualenv provides -extra-search-dir and --never-download command. So you can prepare the setuptools beforehand, copy it from U-disk,using scp, or other solutions.
Move setuptools-0.6c11-py2.7.egg to /usr/local/bin.
Finally we can use virtualenv by
virtualenv -p /usr/local/bin/python2.7 --extra-search-dir /usr/local/bin/ --never-download venv