I recently made a django project using virtualenv on my mac. That mac broke, but I saved the files and now I want to work on my project using my linux computer. I am now having some difficulty running the virtual environment in Ubuntu.
Does it even make sense to try and use a virtual env made in Mac OS on Ubuntu?
Thanks
You can just recreate the virtual environment on Ubuntu. The virtual env will have the python binary which will be different on a different system.
Install pip
sudo apt-get install python3-pip
Install virtualenv using pip
sudo pip3 install virtualenv
Create a virtual environment
virtualenv venv
You can use any name instead of venv.
You can also use a Python interpreter of your choice
virtualenv -p <python2> <python3> <python3.7> venv
Activate your virtual environment
source venv/bin/activate
You only have to recreate virtualenv. That's all.
If you have a requirements.txt file then use pip to install the requirements:
pip install -r requirements.txt
Related
I have set up a virtual environment correctly have activated it and when I do "which python" it tells me the correct directory, but when I do pip install in the venv it installs the package in the default directory of the mac and not in my venv. I have tried using pycharm and installing packages with that, but it happens the same thing.
Edit:
Following I will do a walkthru of my steps, first I did python3 -m venv /path/to/new/virtual/environment, then I did source env/bin/activate, then I did which python and I got the intended directory, afterwards I did pip3 install numpy and I saw the installation process, then I did pip list and numpy was not there, I checked the directory manually and it still was not there. I retried all the same thing with pycharm with the same results.
Follow these steps in order -
In your current working directory :
python3 -m venv venv
source venv/bin/activate
(venv) pip3 install library_name
To check if libraries were properly installed or not :
(venv) pip3 freeze
and check if your installed libraries is displayed on the terminal screen or not.
To deactivate the virtual environment :
(venv) deactivate
This is due to permission issues
Run this command to change permission of your virtual environment folder
sudo chmod -R 777 venv
After activating your virtual environment
source venv/bin/activate
Then try to install Django by either Python3 or Python2
pip3 install django or pip install django
Then check the list of installed packages by either Python3 or Python2
pip3 list or pip list
NOTE: If you run sudo pip3 install django or pip install in virtual environment that is not writeable by default it will be installed outside of virtual environment
If you run pip3 install django or pip install in virtual environment that is not writtable by default it will be installed outside of virtual environment you will get OS Persmission Error
I have used pip3 and pip because you can install packages by either Python3 or Python2, thing to remember if you created virtual environment by Python3, use pip3 and if you created by using Python2 use pip.
I am trying to properly install python and set up virtual environments to make project development easier. Im stuck on how to install pip now. My question is this:
Do I need to install pip in a specific way if I'm trying to set up virtual environments?
Here's what I've done so far...
installed pyenv
used pyenv to install python version 3.7, 3.8 and 3.9
set global pyenv to be python 3.9
Now I don't know hot to set up pip.
I did this:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
and then:
python get-pip.py
..however when I go to verify pip was installed i get 'pip command not found'.
How do I properly set up pip so that I can create virtual environments and install packages for different environments?
Do I need to add pip to my PATH? If so, how do I do that?
You can create virtual environment directly from python with venv
(documentation: https://docs.python.org/3/library/venv.html)
Example:
python3 -m venv /path/to/new/virtual/environment
Activate the virtual environment
source /path/to/new/virtual/environment/bin/activate
Then you can install any package with
pip package-to-install
I made Virt2 virtual environment.
using $ python -m venv Virt2.
I want to install my custom packages in "site-packages" directory. However packages are installed in "dist-packages" directory.
what should I do to install packages in my python virtual environment site-packages??
my python version 3.6.2 (in /usr/local/bin)
You use sudo and sudo switches user to root, i.e. you're completely outside of you virtual env. System pip3 outside of virtual env installs packages into a system directory which is dist-packages.
Run pip install inside you virtual env without sudo.
How do you install virtualenv correctly on windows?
I downloaded virtualenv1.9.1 from here and tried installing it with:
python virtualenv.py install
but it does not appear in MyPythonPath/Scripts
I tried the same way installing virutalenvwrapper-win and it installed correctly. But I can't use it because I don't have virtualenv
python.exe: can't open file
'MyPythonPath\Scripts\virtualenv-script.py': [Errno 2 ] No such file or
directory
The suggested way to install Python packages is to use pip
Please follow this documentation to install pip: https://pip.pypa.io/en/latest/installing/
Note: Python 2.7.9 and above, and Python 3.4 and above include pip already.
Then install virtualenv:
pip install virtualenv
Since I got the same error as mentioned in the question inspite of installing with:
pip install virtualenv
I would like to add a few points, that might also help someone else solve the error in a similar way as me. Don't know if that's the best way, but for me nothing else helped.
Install virtualenv
pip install virtualenv
Move into Scripts directory
cd C:\Python27\Scripts
Create a virtual env.
python virtualenv.exe my_env
Activate the virtual env.
my_env\Scripts\activate.bat
Deactivate the virtual env.
my_env\Scripts\deactivate.bat
install virtualenv
pip install virtualenv
create a virtual environment
python -m virtualenv demoEnv
Activate the environment
demoEnv\Scripts\activate
To deactivate
deactivate
There is an other way to install Python packages.
1: download the package, you want
2: open commander (press the win start-button and search for cmd)
3: cd into the folder where you downloaded your package
4: type: "python setup.py install"
For installing virtualenv, you'll have to either install it using pip as mentioned in the answer by woozyking or you'll have to do something like this:
$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.9.1.tar.gz
$ tar xvfz virtualenv-1.9.1.tar.gz
$ cd virtualenv-1.9.1
$ [sudo] python setup.py install
The command which you have used can be used to create a virtualenv. I would recommend you go through these small videos on virtualenv and virtualenvwrapper to get a better understanding:
python-power-tools-virtualenv
virtualenvwrapper
Creating a Virtual Environment on Windows
1. Create a virtual environment
python -m venv myenv
2. Activate
.\myenv\Scripts\activate
3. Extra information
To disable write
deactivate
These commands will also work on windows
myenv\Scripts\activate
myenv\Scripts\activate.bat
.\myenv\Scripts\activate.bat
Be careful with slashes:
myenv/Scripts/activate.bat
I prefer using this naming:
python -m venv .venv
.venv\Scripts\activate
4. Screenshot
5. Sources
https://code.visualstudio.com/docs/python/tutorial-django
https://code.visualstudio.com/docs/python/tutorial-flask
In my Ubuntu 12.04 machine, the installation of pip requirements is asking me for sudo permission every time it attempts to install. How would I override this, as this is terrible for my working environment to install things globally instead of inside the venv?
Note: I did not setup the venv using sudo.
Have you activated your virtual environment? Run:
. bin/activate
in your shell. Then the local pip installation will take over the system one.
Thanks to #MartijnPieters, I found a workaround:
Running
~/.virtualenvs/myapp/bin/pip install -r requirements.txt
Instead of just
pip install -r requirements.txt
Make sure you use a recent version of virtualenv itself, the latest at the time of writing is 1.7.2. Old versions required the use of -E switch, to install into the virtual environment.