How to activate an existing virtualenv projects? - python

I'm a beginner to Django and Python, and I've never used virtualenv before. However, I do know the exact commands to activate and deactivate virtual environments (online search). However, this learning course takes time and sometimes I need to split the work over 2 days.
When I create a virtualenv today and do some work, I'm unable to access the same virtualenv tomorrow. Even when I navigate to that folder and type in .\venv\Scripts\activate, it says "system cannot find specific path".
How can I open already existing virtual environments and the projects within them? Could it be that I need to end my previous session in a certain way for me to access it the next time?

Even though pipenv had so many problems. I suggest you use it when you are new to virtual env.
Just
pip install pipenv
cd $your-work-directory
pipenv shell
Then you created your project env.
You can active it by:
cd $your-work-directory
pipenv shell
You can install packages by:
cd $your-work-directory
pipenv install $yourpackage --skip-lock

Open the command prompt
Go to the project directory, where you created virtual environment
And type the same as error shows, as in my case it was
File D:\Coding files\Python*recommendation-system\venv\Scripts\activate.ps1* cannot be loaded because running scripts is disabled on this system.
So I typed recommendation-system\venv\Scripts\activate.ps1
And it resolved my problem.

Use this and it will work:
cd $working directory u have virtual env on
pipenv shell

you can use this command it worked for me for reusing your existing venv
$ workon then the name of your existing venv

Related

Python - Pipenv not display in the Python interpreter

I installed and activated pipenv in my project folder, but then I couldnt see the Pipenv in the list of Python interpreter. This is the steps I did:
Create new project folder, cd to this folder.
Install pipenv: pip3 install pipenv
Activate it: pipenv shell
Then I check the Python interpreter, but the pipenv is not in the list.
Anyone know how to solve this? Thanks in advance!!! Im using Mac btw.
I cannot embed the screenshot to this post, so I attach the screenshot here.
Oh, I just figure the manual way to do it, sorry I am newbie so it may seems too simple for many of you haha, post here in case anyone needs it:
After activating pipenv (using pipenv shell), you will notice there're few lines in terminal informing that virtual environment has been created successfully, something like this:
✔ Successfully created virtual environment!
Virtualenv location: /Users/zoey/.local/share/virtualenvs/part_manager-GqnnAfaN
Creating a Pipfile for this project...
Launching subshell in virtual environment...
Open the list of Interpreter using Command Shift P in macOS, select Python: Select Interpreter
Select Enter interpreter path...
Paste the virtual location path in step 1 and press Enter, for e.g. in my case it is /Users/zoey/.local/share/virtualenvs/part_manager-GqnnAfaN
Done, the pipenv interpreter will be displayed accordingly in the bottom left of your Visual Studio Code.

How to make pipenv install virtual environment in project folder on Windows 10

I want to fully understand how pipenv works.
I created my project and would like virtual environment also be in same project folder.
However pipenv installs virtual environment in C:\Users\username\.virtualenvs.
With that, if I change the name or location of my project path, the virtual environment will be lost.
So how can I install virtual environment inside project folder?
I read about setting variable PIPENV_VENV_IN_PROJECT but I did not understand where and how should I do that using Powershell in windows.
Can somebody advise?
Create a .venv folder in your project root. Then run:
pipenv shell
Obviously run that from a terminal session in your project root. Pipenv should check to see if there is an empty .venv and if it finds one it should blow your virtual environment into that.
You should add PIPENV_VENV_IN_PROJECT=1 to the Windows 10 User variable
Check out this for step by step process link where I mentioned the process with images
if you can't open: https://gist.github.com/Saketh-Chandra/28ac93aca0afb8a627ef66edaf575b0d

How to fix 'conda env switching' problem while changing directory?

I want to use my own virtualenv which is created by conda in Ubuntu 14.04.
But the problem is that the virtualenv is switched to base while changing the directory using cd command.
conda activate py2 # using own virtualenv 'py2'
cd ..
# Then, the virtualenv will be deactivated and eventually switched to base env.
How can I use my own virtualenv continuously before I explicitly type
conda deactivate?
Oh I find the answer and it was just zsh(bash) issue.
Actually, I am using zsh which is forked from this git repository.
(https://github.com/wookayin/dotfiles)
This package included some auto-switch functions while changing directory for users' convenience.
In conclusion, it was not the problem but just an additional function.

virtualenv doesn't activate after system 'macOS Sierra' restart or work folder deactivate

I have problem with virtualenv when working in macOS Sierra, it affect only one of the work folders, that make it very weird for me to get why is happening, when setup the new virtualenv I'm designating folder for it and install it there, after activating it all is working fine till I deactivate the virtualenv or restart the system, than I'm getting this:
~/Development/DjangoDEV/FlowersVibeShoppe/venv-flowersvibe-oscar on master
$ source bin/activate
-bash: bin/activate: No such file or directory
If I try to list the existing virutalenv it showing it there:
~/Development/DjangoDEV/FlowersVibeShoppe/venv-flowersvibe-oscar on master▲
$ lsvirtualenv
venv-flowersvibe-oscar
The virtualenv is there, however don't want to activate, I did uninstalled and setup again from scratch like 4 times the result is always the same for this folder, and this affect only one of the work folders the rest of my virtualenv are working fine. Can some one HELP?
Thanks
lsvirtualenv is a command from virtualenv-wrapper, not from virtualenv itself. That project has a separate command for activating virtualenvs: workon. So you should do:
workon venv-flowersvibe-oscar

Virtualenv installing to local instead of virtual

I am trying to install OpenERP server into a virtual enviroment that I created for that. I created the virtual using
mkvirtualenv openerp_rev5054
On said virtual enviroment I use
> (openerp_rev5054)user#machine:python setup.py install --record files.txt
And gives that I have no permission, and if I install it with root access, it goes directly into my python local install. Here is a sample of my files.txt with the location of all the files installed.
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/import_xml.rng
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/release.pyc
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/netsvc.pyc
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/loglevels.pyc
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/__init__.pyc
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/sql_db.pyc
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/release.py
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/http.py
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/PKG-INFO
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/pooler.py
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/loglevels.py
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/pooler.pyc
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/__init__.py
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/exceptions.pyc
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/sql_db.py
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/http.pyc
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/netsvc.py
/usr/local/lib/python2.7/dist-packages/openerp-7.saas_3-py2.7.egg/openerp/exceptions.py
I have a couple of others already installed and the procedure was the same so I see no reason why this one should behave different in any way. Has anyone encountered an issue like this?
Try installing with pip rather than setup.py. I hear that pip plays nicer with virtual environments.
Check to make sure that your virtualenv is activated. If it is, you should have an environment variable $VIRTUAL_ENV that has the value of the root directory of the virtualenv. Or, more commonly, you'll see a change in your shell prompt.
If it is activated, make sure that your $PATH is correct, perhaps something else has come along and changed it. which python should point at a python inside your virtualenv bin directory.
If you have an old version of virtualenv, ensure you're using --no-site-packages

Categories

Resources