Windows 7: What PATH to set to when using Conda - python-3.x

I've got anaconda installed and was able to create a Python 3.3 environment. I can switch to it and conda info -e shows that I've switched.
However, I'm confused about what to set my PATH variable to. If I hard code it to the exact env then it works, but I thought that the purpose of conda was to be able to switch easily, as well as update and maintain various environments separately.
Perhaps I misunderstood and there's no way around setting my PATH everytime...

In the Windows cmd shell, use the activate and deactivate commands to change the PATH automatically. For instance, if your environment is called python3, run python3 to "activate" (i.e., add to the PATH) the python3 environment. Use deactivate to remove it.

Related

How to make your default path as base for anaconda?

I have been using anaconda(in which most things are preinstalled) for a while now but recently switch to miniconda. atm whenever I need to run miniconda I have to set the source as source ~/miniconda3/bin/activate then I would see Base in my path and conda commands works otherwise conda command does not work. Can you please guide me on how to set my source as default on mac?

Taking a conda environment to another PC efficiently

This may be a noob question, I am new to using Conda environments. I am looking for some advice on how to tackle the following workflow in the best way.
I have both a work desktop and a desktop at home. I want to be able to, at the end of the day, take my work environment home.
Note: I work in Ubuntu on subsystems for windows
Say I start a project from scratch. I currently use the following workflow:
I create a conda environment.
conda create --name my_new_project python=3.10
activate my workspace.
conda activate my_new_project
I install python packages I need:
conda install -c conda-forge opencv
etc...
At the end of the day I want to copy that environment and take it to another PC, so I do the following:
conda env export --f my_new_project.yml
Finally on my home PC I do
conda env create --file my_new_project.yml
This works but requires me to make a new environment every time I switch PC. Is there a way to load the differences between the two conda environments and only add the new packages? Or is there another better way to tackle this?
There's no need to create a new environment every time. You only do that once and then update the existing environment, i.e. use the following as step 5:
conda env update -f dependencies.yml
I also suggest you to put your code, including the dependencies file, into version control if you aren't doing that already. Then, getting up to speed with your project on a different computer will only require two steps.

Starting with anaconda on Ubuntu 18.04

I installed latest version of Anaconda3-2020-02.
I was trying to follow this instruction in order to create environment for running with python==3.6 instead of python==3.7., because I have python 3.6. installed.
So, running the
conda create --name snakes python=3.6
and then activating my environment with conda activate snakes, it enters environment (snakes). However there are no anaconda packages inside like jupyter notebook or others, no anaconda-navigator... So whats the purpose of it and how can I run these programs from environment?
Also, for some reason (when I am not in the environment, just regular bash shell) $PATH is not set up to the /bin directory in anaconda, just to /condabin. Can you explain this also, because I am not able to run nothing except conda command from shell after recommended installation.
If by default after installation environment is not activated, you should activate it by sourcing a file anaconda3/bin/activate. You will see indicator (base) on the left of your bash prompt.
Good thing about anaconda3-2020-02 is that it is not messing with system python, as newest python is being launched inside environment and proper$PATH is set up just inside environment. If only, for some reason, specific version of python is needed, then it makes sense to set it up with this instruction. I would be just using default one with python 3.7 probably from (base) environment.
Keep in mind that by default anaconda components are not being set up inside new environment being created. In order to bring them, for example jupyter, you should run the command like this:
conda create --name snakes python=3.6 jupyter

Set the PYTHONPATH for a older version of Python to a directory where I want to install it though I have a default version of Python3

I am using ubuntu 18.04. I have Python-3.6.6 installed as a default version. But for practice I have installed Python-3.6.5 from source code to a directory where I wanted to install it and changed the .bashrc file accordingly. But it is showing me the default python3 path when I call "which" command.
How to use the python version which one I have installed recently?
If you only want to run some practice scripts you can select directly which python you want to use for your script. In the command line, e.g. type
PYTHONPATH=/foo/bar/python365 python somescript.py
where /foo/bar/python365 points to your python-3.6.5
You can also change your PYTHONPATH variable to look first in the python-3.6.5 folder before it looks to the default python (3.6.6) you had installed before. However, I do not recommend this, since it will make all python applications choose the python-3.6.5 as default. For extended practice with python-3.6.5 consider a virtual environment or an anaconda environment.
You should use virtualenv or something similar, like pipenv, I myself use virtualenv.
Here's a guide on how to do that: https://docs.python-guide.org/dev/virtualenvs/
virtualenv is a bit lower level and so not that intuitive to use, but since I used virtualenv before I found pipenv, I just stuck with it, while adding a few aliases to my .bashrc to make it easier.
I used two different python versions because discord.py would break on 3.7 (that doesn't seem to be the case anymore, but I still have it setup with 3.6 and 3.7), so here's what my .bashrc for two different versions looked like, this is on windows, but if you are on unix system or macOS (I want to make this answer as general as possible, it works the same on all operating systems really), just change the paths to lead to your interpreters (whichever you have) and don't use winpty:
alias python36="winpty C:/Users/Hevaesi/AppData/Local/Programs/Python/Python36-32/python.exe"
alias python37="winpty C:/Users/Hevaesi/AppData/Local/Programs/Python/Python37-32/python.exe"
alias pip36="C:/Users/Hevaesi/AppData/Local/Programs/Python/Python36-32/python.exe -m pip"
alias pip37="C:/Users/Hevaesi/AppData/Local/Programs/Python/Python37-32/python.exe -m pip"
alias venv36="python36 -m virtualenv"
alias venv37="python37 -m virtualenv"
alias python="winpty python"
Now, to use Python 3.6, I use venv36 venv in my project folder, and it setups Python 3.6 environment, using venv37 venv would create Python 3.7 environment.
I also wrote a function to make activating less of a hassle (again, this is in bashrc)
activate() {
if [ "$#" == 1 ]; then
source "$1/Scripts/activate"
else
echo "Usage: activate <env_name>"
fi
}
So, after I created my env once, I go to project folder, type activate venv and it starts up whatever version I wanted the project to have all by itself, to run my project I just use python myfile.py, when virtual environment is activated, it will use the interpreter that's in active virtual environment, regardless of what you have in your PATH variable. Also, using pip will automatically install to your virtual environment, not your actual installation, meaning global package list will be clean, or in best case, completely empty.
You should only install what you need and keep it separate environments, normally you use a single environment per project. Well, unless your project is client/server at once (for whatever reason) and server uses different libraries than client, for example, more of them, client environment could have less modules since that's what the server is for, to provide something without having to do it yourself, so they could be two projects in one, hence two different environments, separating dependencies based on what the "unit" in the project really needs.
Note: you have to install virtualenv (or pipenv or whatever you want to use really) into all of your python installations, if you want to create virtual environments from them, that's what pip36 and pip37 here is for - for installing packages directly into actual python installations, for now, I only had to do pip36 install virtualenv and pip37 install virtualenv.

Pycharm and Python Paths on Windows with Conda

I am working with multiple versions of Python, so I don't want to put any one of them in my windows path. I discovered that I can create a virtualenv (under Settings -> Project: X -> Project Interpreter and that will allow me to specify which python exe to use, but also where to get other useful programs, like pip. The end result is that using Virtualenv I can type "pip" or "python" in the terminal in Pycharm and use it as a regular terminal.
But now I'm working with Anaconda so I don't want to use virtualenv and I want to use conda instead. This works fine, but it doesn't seem to put anything into the path. (This is particularly important because where I intend to keep my project is not near my path to the python environment conda created.)
So if I type "pip" or "python" in the pycharm terminal, it doesn't recognize them. I have to specify a huge path to get it to work right.
I've been googling around and trying to find a solution to this problem. I've found a number of supposed solutions, but so far none have worked.
So, for example, I've already tried Add Content Root under project structure. This does nothing. I've tried add local, which seems to just screw everything up. (Presumably this is a way to create a local environment that I shouldn't be touching in conda.) I've tried adding a PathConfig.pth file. So far nothing works.
Remember, I don't want to add anything into the windows path (which obviously would solve my problem) because then it won't know which specific environment I want at the moment.

Resources