Miniconda virtualenvs activation 'source activate' vs. 'conda activate' - python

Installed miniconda
created my first virtualenv called ai37 (python 3.7)
created my 2nd virtualenv called da35 (python 3.5)
Will it be an issue that I created a new env called da35 without first deactivating my first created env called ai37...meaning did I create a virtualenv nested in a virtualenv? when i tried to use
$ source activate da35 the output said
source: no such file or directory: activate
so I then deactivated it and tried it again however when using
$ conda activate like it says to, I think I activated a directory within a directory and had to enter deactivate twice to get back to my base. Any help understanding this?
I was learning from this video and the guy did it but his 2nd source activate cmd didn't output the same. https://www.youtube.com/watch?v=23aQdrS58e0
I previously installed homebrew so already had python 3.8. I also installed eclipse and virtualenv and pip already came with the homebrew packages. Basically I learned of miniconda as I had just finished setting up my first virtual env with the 'pip/virtualenv' way only to find conda has greater flexibility.
For context, when I entered
$ conda env list
I also got the
"/Users/meusr/opt/miniconda3/lib/python3.8/multiprocessing/resource_tracker.py:216:
UserWarning: resource_tracker: There appear to be 1 leaked semaphore
objects to clean up at shutdown warnings.warn('resource_tracker:
There appear to be %d '"

Related

How to choose executable which runs a virtual environment

How does one create virtual environment that runs on it's own executable?
I used anaconda to create new Venv (to experiment with installing new modules) by cloning some old Venv
conda create --prefix ./new_env --clone C:\full_path_to_old_env\old_env
But new Venv is still using the "python.exe" from old Venv, as can be seen by calling
import sys print(sys.executable)
Because of that, when I install new modules, using for example
pip install selenium
inside the new Venv, it gets installed in the folder of new Venv (as expected) and is unreachable for old executable.
I saw similar question addressed here Changing Python Executable by changing where to install new modules, but that defeats the idea of independent environments.
The only way to for Venv to run it's own copy of python I found is using
sys.executable = r'C:\full_path_to_new_venv\python.exe'
at the beginning of the notebook, but this seems more like forced patch, rather than solution.
This also gets overridden with every initiation of new Venv, so all notebooks running in new Venv would need it
I found what was wrong: I was using Jupyter Notebook to run python virtual environments. But I did not install ipython kernel to new VEnv
Apparently, in such case Jupyter doesn't throw an error when a kernel exists somewhere else and just runs the kernel it found.
Hence, the fix is to install ipython kernel to new VEnv:
$ipython kernel install --name .venv --user

Pip in pycharm install packages in conda env and not in active venv inside project

i'm having a weird problem...
I can install packages using the built-in package manager in pycharm. But for some reason everytime i use "pip install (xx)" it is installing the packages in a conda env somewhere on my mac...
How can i solve this ?
I've tried the following:
close --> reopen pycharm //
deactivate and activate the venv //
Checked project intepreter is the right one (which it is...)
You're inside the virtual environment venv, while being inside the Conda base environment (note the (venv) and (base) to the left of your prompt). Conda is likely overriding your venv's pip.
My bet as to why this is happening is that, during installation, you set Conda to autostart its base environment whenever a new terminal is open (be it inside PyCharm or not).
You can try to either:
exit Conda (with conda deactivate) and try pip install again (check to see that you're still inside the venv virtual environment).
install the packages directly from PyCharm's GUI - note the small + sign on the bottom-left of the package list. This won't solve the issue related to your terminal, but will function as a workaround for now.
Note that these aren't guaranteed to work, because you may have additional configurations on your system (either installed directly by you, or indirectly by Conda when you installed it).

How to activate an existing virtualenv projects?

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

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.

How to tell if virtualenv is activated in Windows Git Bash

I created a virtual environment in my new directory with virtualenv env and then in Windows Git Bash ran env/Scripts/activate, which seemed to work. I didn't notice my virtualenv being displayed in parens at the beginning of the line (question1: can I set it up to work like that?), so to check if it was indeed activated I ran pip -V which gave me:
pip 9.0.1 from c:\tools\python2\lib\site-packages (python 2.7)
Shouldn't that be giving the directory of my virtualenv rather than site-packages? I also ran pip list and it gave me a list of installs that I had (naughtily) installed globally for a different project. So I can only assume my virtualenv did not activate and I don't know why that is.
Your suspicions are correct. Try source Scripts/activate. What you did will run the command in a new and temporary shell instance.

Categories

Resources