VirtualEnv is installed, but cannot find bin/activate - django

We had a working project with git, and our instructor moved our project over to mercurial after making some changes.
I pulled the new project and started it up under a new folder.
I tried running a virtualenv for the new project but I get: Requirement already satisfied
I would usually then run $ . bin/activate but I cannot find a bin folder.
How do I get a virtualenv setup for this project at this point?

The place where you have your project isn't necessarily the place where you have the environment. Did you have the environment in git too?
Perhaps what you need to do (in case you don't have a versioned environment) is recreate the environment (virtualenv environment), install the dependencies (pip install -r req.txt) and then activate it (source path/to/environment/bin/activate).
Good luck.

Ok
Try this an awesome link to How to install django in virtual environment .
http://ayarshabeer.com/post/50973941605/install-multiple-django-version-using-virtualenvwrapper

Use the following steps
virtualenv virenv_name --no-site-packages - create new virtual environment in git
pip install -r requirements.pip - It can be used for install tools in
(requirements.pip files)
yolk -l - It will used for list install files
source git/virenv_name/bin/activate - Activate virtualenv
deactivate - Deactivate virtualenv

Related

how to activate existing virtual enviroment (using pipenv)

I am working with a project in django where i am using virtual enviroment using pipenv shell (which created enviroment name (Django_and_Rest-YRrszWnq)) so in this enviroment I have installed many packages releated to this project
Now I started new project and also i want to used above virtual enviroment How to activate this ((Django_and_Rest-YRrszWnq)) enviroment to new project using pipenv command ?
From the environment (Django_and_Rest-YRrszWnq) run pip freeze > requirements.txt and then copy the requirements.txt file to the new project. Then from inside the new project folder, run pipenv shell this creates a new environment. Then run pip install -r requirements.txt. Now you have a new virtual environment with the exact dependencies as the old environment.
If you find this solution helpful, kindly upvote the solution. Thank you.
Try this -
. ~/.local/share/virtualenvs/Django_and_Rest-YRrszWnq/bin/activate

Python venv not creating virtual environment

I'm trying to create a virtual environment for my current Django project using
python3 -m venv env
however the command doesn't create any directory with bin/include/lib folders.
What exactly am I missing here?
I have a Windows 10 machine and had a same problem. It was because I had multiple versions of python. Unknowingly windows had created a python.exe in the WindowsApps folder -
Then the solution is sometimes:(there is a huge chance that, the old %PATH% got renamed)
py -m venv venv
This python.exe had a size of 0 kb, so I deleted the python.exe in the WindowsApps folder, opened a new Command prompt and it started working.
Sometime system's path environment is not aware of virtualenv.exe
solution:
install virtualenv
pip install virtualenv
run command in the directory where you want virtual environment :
python3 -m virtualenv venv
For anyone facing this issue now, simply changing the command to start python instead of python3 fixes this
why do you have to write python3 -m venv env when you base is installed as python3.6 itself?
Just do pip install virtualenv this should install virtualenv package if not already installed, then
virtualenv envname this will run and should give you a message like this, I have created a env called testenv:
C:\Users\Admin\python_projects\venvs>virtualenv testenv
Using base prefix 'c:\\python37'
New python executable in C:\Users\Admin\python_projects\venvs\testenv\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
If you get this, it is a success, else do let us know what you get, after this you must cd into the Scripts folder and then run activate
I was having this same problem. I was able to get venv working by uninstalling Python and reinstalling it (I'm using the Anaconda distribution). The py -m venv test command still doesn't have any output after running it, but now it creates a folder for me and I can activate the test environment.
Try this (works for me)
python -m venv C:\<optional-EXISTING-directory-path>\<VENV-name-u-want-2-use>
For more info: https://docs.python.org/3/library/venv.html
Install and create through:
pip install virtualenv
virtualenv <your_virtualenv_name>
Then activate the environment, by going to ./your_virtualenv_name/Scripts folder and then run:
activate
I guess I am a bit late to answer the question, but before creating a virtual environment always check if we already have a .venv hidden folder
Navigate to the directory where we want to create a virtual environment
Check if we already have one by ls -la this command will show us the hidden folders, as .venv will be hidden by default
If we do not have the .venv folder (name is up to us), then create one by mkdir .venv to follow the best convention, in this folder we can create multiple virtual environments
Now we can create a virtual environment by python3 -m venv ./venv/drf
In above folder we have created, inside that we are creating one more folder drf (Django Rest Rramework)
At last to run our virtual environment use source .venv/drf/bin/activate by this command we are running the script which is there in bin folder
I hope I was able to explain, as I am also learning
Please feel free to edit or make any changes in the post, If something is wrong
pip install virtualenvwrapper-win
try to install it and do it again
I just had the similar problem, and I realized changing the path directories names by removing the spaces in the name of the directories helps.

how to bring out django project from virtualenv

I have django project in virtualenv and now I am publishing it in server but the problem is I can not move project from virtualenv, when I do this then related packages inside site-package, cant be read and errors occur, how can I bring out my project from virtualenv without any issuing
Create a new virtualenv on the server. It's easy
Step 1 Get the list of modules in the current virtualenv
source /path/to/current/bin/activate
pip freeze > /tmp/requirements.txt
Step 2 Create a new virtualenv. Login to your new server, copy the requirements file there. Then either change into a suitable directory before excuting the virtualenv command or give a full path.
deactivate
virtualenv -p python envname
Step 3 Install modules
source envname/bin/activate
pip install -r /tmp/requirements.txt
That's it.
As #bruno has pointed out, you really should be using a virtualenv on the server. And you should be using it on your local dev server as well. Then you can be really sure that the code will run at both ends without any surprises.

Duplicate the virtual environment for production

This may be a silly question, but I would still like to ask:
I am developing a project using Django, CherryPy, and Nginx. I noticed that a file requirement.txt is usually created to indicate the packages and versions installed in the development environment. Suppose the directory of the virtual environment is /home/me/project/python2Venv.
When I deploy my Django project (tango) into production, the project is copied to the production directory:
sudo cp -r /home/me/project/tango /webapps/tango
For the virtual environment, may I just copy the whole directory using the following command or I should install each of the packages into the production environment again according to requirement.txt?
sudo cp -r /home/me/project/python2Venv /webapps/tango/python2Venv
I think virtualenv uses absolute paths in some files so recreating the env and installing the packages via requirements.txt would be more safe.
In my opinion, it is recommended to install the packages with requirements.txt. Copying directory, can end up being a nightmare.
Say in Update 1:
You have 4 packages each with a specific version(pkg1-ver1, pkg2-ver1, pkg3-ver1, pkg-ver1).
In Update 2:
You have upgraded one package to its new version(pkg1-ver2). With requirements.txt you would just upgrade that one package. Instead of the copying all the packages(Although, i am not sure how well copying of the directory would work).
Hope this helps !
You should install packages with the file requirements.txt.
Or you can use virtualenvwrapper. It helps to clone virtual environments locally easily such as cpvirtualenv, rmvirtualenv, etc.

How to install image processing just for a virtualenv project with pip for django

But I'm looking to install freetype, libjpeg, PIL build to add image processing to my django projects I've followed this installation http://dakrauth.com/blog/entry/python-and-django-setup-mac-os-x-leopard/ which installs it site wide but I can get it inside my virtualenv project.
Do I just cd into the working directory of the virtualenv (project) and install it there and will it just be available for that project or do I use pip? I couldn't find the packages in the pip repository. Can someone enlighten me please.
curl -O http://pypi.python.org/packages/source/d/distribute/distribute-0.6.21.tar.gz
tar -xzvf distribute-0.6.21.tar.gz
cd distribute-0.6.21
python distribute_setup.py
easy_install pip
pip install virtualenv
virtualenv --distribute --no-site-packages [myproject]
cd [myproject]
source bin/activate (this activates the sandbox that virtualenv created)
pip install django mysql-python
Go to the working directory of the virtualenv and then run
$ source bin/activate
This will set that virtual environment as your active one. So now that it's active, you can install what you want, either manually (by following those steps on the site you linked to) or with pip and it will automatically install it into your active virtualenv.
If you then, say, run python manage.py runserver while the same virtualenv is active, django will have access to your newly installed package. Once you want to unset that virtual environment as your active one, simply do deactivate.
I ran into something similar; what I did was install it into the default directory (e.g. Python27/Lib/site-packages) then cut and paste all the new files put there into the created environment's site-packages. Hacky, but works.
After that you can follow EEVIAC's instructions to actually get your server running.