how to activate existing virtual enviroment (using pipenv) - django

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

Related

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.

confusion in deploying module's with django

Good day.
I'm a newbie to Django and I have a slight confusion:
When deploying my Django app, do I need to deploy it with all the Python 'come-with' modules, or the hosts already have them installed.
Also, I installed PIL for image manipulation. Would they also have it installed or i have to find a way to install it on their servers. Thanks in advance
do I need to deploy it with all the Python 'come-with' modules
Never do that. It might conflict with the dependencies on the server. Instead issue the following command to create a dependency file (requirements.txt).
pip freeze > requirements.txt (issue this command where manage.py is located)
On the server create a new virtual environment. Now copy django project to the server (you can do this using git clone or just plain old Filezilla). Activate virtual environment. Then change you current working directory to the where manage.py is located. to install all the dependencies issue the following command.
pip install -r requirements.txt
This will install the required dependencies on on server.

How to install Django project with all modules?

I created a Django's application which use some additional modules like crispy_forms. I would like to send this application to my friends to test it.
But I don't know how can they just install it and run it? Is it possible?
Application using also database PostgreSQL.
What is the simplest way to just run this application from any place with no errors and problems on the start?
I found only information about https://docs.djangoproject.com/en/1.10/intro/reusable-apps/
and packed my app, but I don't know how to install it.
To setup env for project i would install virtualenv, then:
pip install -r requirements.txt
You need to set database connection in settings.py, or switch to sqlite3...
hope this helps!
If you are using virtual environment then activate it and go in your project root.
If you are not using virtualenvironment then do the same thing, go in your project root.
Make sure you have requirements.txt file.
run the command
pip freeze > requirements.txt
This will add automatically all your modules to requirements.txt file
which can be then installed by
pip install -r requirements.txt

deploying to heroku from local machine

I have django project running on my machine in virtualenv. Is there a way I can deploy my project on Heroku directly? I followed steps mentioned in heroku documentation but i am kind of confused with req.txt since my project already have req.txt in virtualenv. I am new to django heroku techs. Any guidance is highly appreciated.
my project already have req.txt in virtualenv
You should not have req.txt in virtualenv. You should have requirements.txt in your project repository. requirements.txt is just a list of modules that need to be installed in the virtualenv. You create and activate a new virtualenv, then you run pip install -r requirements.txt, and it installs everything you need in the virtualenv. So requirements.txt is not part of the virtualenv, it's more like a description of how to setup the virtualenv.
If this is not clear, you may find my article, virtualenv demystified, useful.
The requirements.txt file defines what python dependencies Heroku will install. Generally speaking, what you use locally will be the same as your local development machine.
If there are differences, you may opt to have an additional file locally that contains local, development-specific packages (for example django-debug-toolbar).
First you will activate your virtual environment and then go to project root and run the command
pip freeze > requirements.txt
This will automatically add all the dependencies of your local machine in requirements.txt. Once you push the file heroku will automatically detect the changes and install them.

VirtualEnv is installed, but cannot find bin/activate

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