Pyenv: activate local venv - python

I use poetry to manage my projects dependencies and tests. I usually create a new virtual environment for each project, with a .venv directory inside of the project directory.
I would like to use pyenv virtualenv to automatically activate this projects virtualenv when inside the project directory as a local one, eg:
pyenv virtualenv local <my venv that also lives inside of this project>
Is this achievable, or do I have to create my virtualenvs inside the .pyenv directory?

When inside the project directory, any command starting poetry run will be run inside the virtual environment created by poetry.
To avoid having to use poetry run before each command, poetry shell can be used to activate the virtual environment.

Related

Django not recognized in virtual environment altough already installed when inside virtual environment

I've created a virtual environment in my PC(Windows). I've pushed the project to my git repository and now cloned it into my Mac. I activated the virtual environment, and tried running :
python3 manage.py runserver
This error is raised :
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
I understand that the message sent from above is defined inside the manage.py if an ImportError is raised.
What I'm trying to understand is how to make the project to be runnable from multiple systems just by activating the virtual environment.
AFTER cloning the project, I've changed line in my :
pyvenv.cfg
...
include-system-site-packages = true
//previously = false
...
I'm not sure what I did wrong while setting up the virtual environment and installing the packages while being IN the virtual environment.
In your windows pc, inside the activated virtual environment, run
pip freeze > requirements.txt
Add this file to your git and push it to your repository.
After that, in your mac environment, pull the latest git changes and inside the activated virtual environment, run:
pip3 install -r requirements.txt
If pip3 is not recognized, use pip
Finally, run python3 manage.py runserver

Creating Virtual Environment in Windows

I created a virtual environment using conda create -n venv inside the project folder and activated the venv environment. However, I face the following issues:
The venv environment is getting created under C:\Users\Rajesh\anaconda3\envs folder.
When I install packages while in the venv environment, the packages not getting installed in venv folder. Please advise what is going wrong here
The default path of virtual env is located $USER/anaconda3/env, no matter where you execute the create command, the env created will be put in this path. You could change this default path by editing $HOME/.condarc:
envs_dirs:
- some path you like
pkgs_dirs:
- some path you like
Are you sure you have executed conda activate venv before installing packages?

Cannot activate virtual environment on virtual studio

I am using Visual Studio Code and have Anaconda downloaded so i selected it as my path interpreter.
I am able to download virtualenv using pip install virtualenv and then instantiate it using virtualenv env.
The issue occurs when I try to activate the environment using activate env or conda activate env.
Error message returned: Could not find conda environment: env. I then proceeded to look into my directory and I see that the environment is included as a folder so I'm confused on why I cannot activate it. For reference I am using Windows.
Edit: Originally the environment was not appearing in my users/.conda/environments file but using conda create --name venv I was able to create a new environment here. However, it doesn't instantiate in my current directory. Thoughts?
conda virtual environments are not interchangeable with virtualenv virtual environments. If you have created a virtual environment in your current dir. The ps command would be .\Scripts\activate

Can I install virtual environment in two separate directories?

Fact is I have already installed django.
Now I want to install flask. But have no idea how to install virtual environment again in separate directory.
Navigate to the directory where you want your new virtual environment and type:
virtualenv venv
Virutalenv documentation here.

can't enable the Python virtual environment while creating an app on Mac

I am following instruction to create Mac app with Python.
I was installing Virtualenv as a part of it, as here says.
I successfully did till second step; pip install, bash_profile.
But when I try to Enable the virtual environment part, I get a. no file or directory / b&c. command not found, for each step.
By the way, this is the first time I heard .bash_profile, so the script is empty except what I did at the second step.
How can I fix the problem?
Follow simple steps
pip install virtualenv
virtualenv venv # venv is your desired name
source venv/bin/activate
I suggest you read Virtualenv User Guide.
Install virtualenv by using pip install virtualenv
virtualenv ENV to create virtual environment.
Where ENV is a directory to place the new virtual environment.
source bin/activate to activate script.
And type deactivate to undo the changes.
virtualenvwrapper
Add three lines to your shell startup file (.bashrc, .profile,
etc.) to set the location where the virtual environments should live,
the location of your development project directories, and the location
of the script installed with this package:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
Run source ~/.bashrc to reload the startup file.

Categories

Resources