`conda activate` not working in Windows PowerShell - windows

I am running Windows PowerShell inside or outside VS Code in Windows 10, and I am not able to activate or change the virtual environment. I have the full Anaconda installed on my system (this should probably pop up for Miniconda too).
I have already tried the following solutions following other answers here or solutions on the web:
Ensured PATH environment variable points to <anaconda_dir>/Scripts
Ran conda init prior to and after running conda activate <env_name>
Tried solutions provided on https://github.com/conda/conda/issues/9392

Related

PyCharm virtual environment is not automatically activated for zsh terminal, MacOS

I have referenced this question: How do I activate a virtualenv inside PyCharm's terminal?
As it mentions, PyCharm should support auto activate virtual env since 2016. But I fail to get it work.
Above is my setting page for the PyCharm Terminal. I have checked the 'Activate virtualenv'.
But every time I start a terminal in PyCharm, it didn't automatically activate the virtual env. I need to manually use command conda activate <environment_name> to activate the environment.
I am using a Conda Environment installed with homebrew.
May I ask, is there any parameters that I can add to the Shell path (/bin/zsh) to make it automatically activate specific virtual env? Or other ways to solve this problem?
I had it working. This has nothing to do with pycharm.
My issue was about anaconda HKEY_CURRENT_USER was still there even after uninstalling it.
1-You must check your PATH environment variable echo %PATH% in the command prompt and check for paths that do not exist anymore or check for the "&" sign and remove them.
2-The following may be this works for you:
Open the Registry Editor (press the Windows key, type Regedit and hit Enter).
Navigate to HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun and clear the values.
Also, check HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
I have solved this problem with an alternative method found in: https://stackoverflow.com/a/55658404/15416614
Although this question is originally asking about the Windows environment and it is in 4 years ago, there is an answer from 'Ethan Yanjia Li' that can still solve my current problem.
This seems to be a PyCharm bug that the 'Activate virtualenv' option is not working sometimes. It has been fixed before but reappears in some situations, according to: https://youtrack.jetbrains.com/issue/PY-23417.

Why Anaconda installer doesn't recommend adding its directory to PATH on Windows?

FAQ says it's because it "can interfere with other software", but I couldn't find more details on that. The proposed workaround (opening Anaconda from Windows Start menu) is just too inconvenient.
The base environment includes a lot more than just the Conda binaries, specifically it has a Python installation and libraries. Leaving it on the PATH when activating other environments can lead to packages from the base env being loaded, i.e., violating the isolation that virtual environments are intended to have. Hence, in version 4.4, Conda introduced a mechanism (conda activate) to provide cleaner isolation and officially recommended against adding to PATH directly (see Release Notes). conda activate is a shell function that gets added to a shell via some lines being added to the initialization files (e.g., .bashrc).
Since Conda version 4.6, there has been a conda init command so that users can manage this initialization for multiple shells and not just have it added at installation time (see Release Notes). Windows users, for instance, can specifically use the conda init powershell in order to use Conda in a PowerShell prompt.

How to solve [WinError 5] Access is denied in anaconda prompt

I have recently reset my laptop and installed Anaconda in it, and I tried to open JupyterLab but it gives me error
Error executing Jupyter command 'lab': [WinError 5] Access is denied
but it works fine when I try to open JUPYTER NOTEBOOK or try to open JUPYTER LAB with Anaconda as administrator.
I reinstalled Anaconda, and still it gives me the same error. Also it gives me the same error when I try to open JUPYTER LAB from Anaconda Navigator. Before resting my laptop it works fine for me, but now it's not. I tried to search my query on the web before asking here, but I did not get my answer.
I want to run JUPYTER LAB with normal Anaconda prompt
Additional details
My Anaconda is installed in C:\ProgramData (by default).
I didn't check the box “add to path” while installing Anaconda.
You can just run it with Python:
python -m jupyterlab
This should work from an Anaconda Prompt or even the command prompt (if it uses the Python in Anaconda). It does not require admin rights.
Workaround:
open anaconda navigator
click on the jupyter lab settings option and then remove it
Now open your anaconda prompt and type the following command: conda install -c conda-forge jupyterlab
now try to open it.
Proper solution:
If you have installed Anaconda for all users then you will face this issue (thanks to Alok Rajasukumaran, who pointed out this). The best way to solve this problem would be to reinstall this for only the current user.
But if you have a requirement to install for all users, then you can follow these steps:
run the terminal as an administrator
type jupyter lab
Optional (Automating launching jupyter lab with shortcut)
If you want to automate these steps, then you can create a batch file and assign a keyboard shortcut to it. Steps are as follows:
open notepad and write "jupyter lab" and save it as a .bat file
right-click on that file and click on create shortcut.
now open the properties of created shortcut file and in the "shortcut-key" section type any combination of keys you want to set
shortcut.
click on "Advanced" and select "Run as administrator"
Now you can initiate jupyter lab directly by typing your shortcut key and giving "yes" permission to the prompt.
Try to execute as an admin. Problem solved.
This solution is unsafe. When you execute a program with Admin this program has full permissions over the system.
The good solution is to create a new environment with your current system user (not root/admin). Activate this new environment and it would works
Usually, you don't have error in opening jupyter notebook command.
I usually type the jupyter notebook in the path bar in the explorer to open the notebook from that path directly — but as we are having an error in jupyter lab, I was only able to open jupyter notebook from there.
The solution for that is:
Just type jupyter notebook as usual in the command prompt or the path bar in explorer.
As soon as the browser opens automatically, change the URL from:
http://localhost:8888/tree to → http://localhost:8888/lab
Yes, just a one word change. tree → lab and...
Whoo! The jupyter lab is open right there you want it to be!
This is a problem that I see happening for Anaconda 3 installs for all users on Windows. Default (for single user) install seems fine. The permissions are somehow messed up during install. The solution I found is: explorer > right click anaconda3 folder > properties > security > advanced > change permissions > check "replace all child permission entries..." > OK.
This will take a while. After that uninstalling and reinstalling Jupyter Lab worked well.
The problem I had is that it installed the application in users/<your username>/anaconda3/.
To solve this I simply manually moved the folder with its contents to c:/program files/.
Avoid running as Admin due to security concerns. The fastest way is to create a virtual environment and install it there. This is what I did and it did not require any reinstallation of Anaconda or running it as Admin.
in anaconda prompt:
conda create -n myenv python=3.9
conda activate myenv
conda install -c conda-forge jupyterlab
jupyter lab
the last line will launch the jupyter lab.
I want to emphasize what was written only as a comment, because it is easier to find it as an answer than to browse all comments:
If you are using Windows and installed it for all users, you will get this error.
The easiest way is to reinstall Anaconda only for you.
Note: You may uninstall your previous (unsuccessful) installation (for all users) before reinstalling it for only one user (you). But it is possible to do it later, too.
What I did is to create a new environment in Anaconda Navigator. I had the default environment which was root, so I could launch applications only as root.
In the Anaconda Navigator Home screen click on Environments -> Create. Here is the guide to create a new environment https://docs.anaconda.com/anaconda/navigator/tutorials/manage-environments/

Migrate Anaconda packages to `venv` virtual environment

I have installed Anaconda recently in a new Windows computer. I have no experience with managing installed packages in Windows, but in Linux. I created a new project with PyCharm and chose to use as interpreter Python 3.7 that I installed separate from the Python 3.6 version that Anaconda comes with. Now I want to be able to use Anaconda modules such as numpy or pandas in my PyCharm Project, that is using a virtual environment set up in a PyCharmProjects folder.
I fail to understand how exactly should I do it. What is that I have to copy or run to migrate the Python packages installed in Conda to my Virtual environment created from a clean independent install of Python 3.7? When I try to import them they don't work. Do I have to create a new project and migrate the files or can I do it without that?
Edit
Also, I am very unclear about how I can run Python36 that Anaconda installed. There is no conda command in Windows and python runs python27. How do I do this?
So it seems that using Python in Windows goes a bit differently than in Linux/MacOS. In order to change the default version that runs when python command is executed, one has to run the command regedit and Find (Ctrl+F) Python.exe, and change the path to default Python interpreter that one wants to use. Python installed by Anaconda can be found in Anaconda's folder in C:\ProgramData (if installation was for all users, if not its probably in some other folder in C:\Users\[User].
As for the other part of the question, I'm not sure but I think packages have to be re-installed in the virtual environment, unless you know how to copy the files one by one. Also, it's important to be careful with the version compatibility. In my case, the two Python installations are different versions, so it might not work the trick to copy the files. Other option is to change where the interpreter runs; if in that folder the packages are installed, the installation will succeed. You can also change Python's path to find packages; but that is something that must be done programatically and is not very handy to have to be running those lines of code each time.
When creating a project (or even when the project is already created) you can choose to change the interpreter to Anaconda's Python, even if you are not using conda as a package manager, but virtualenv by Python. That'd be the trick for me. Aditionally, PyCharm also natively integrates package installation into the virtual environment in a GUI menu.
If anyone has a better answer/explanation, I'm looking forward to getting to know it, but in the meanwhile that is the conclusion I have arrived to.

Anaconda navigator VERY slow

My anaconda navigator takes 2-3 minutes to start. I have proxy setting set correctly and I can use conda install with no problem.
Why is Anaconda Navigator so slow?
I had the same problem. My issue was the ssl verification as I assume my workplace has done something with Firewall or etc. So I took the following two steps to fix it:
- open command prompt (cmd.exe)
- You can see the list of conda settings: conda config --show
- Disable the ssl verification: conda config --set ssl_verify False
Now launch the Anaconda. If it takes time, wait! It will finally load.
- Go to File->Preferences (shortkey: Ctrl+P)
- Make sure to uncheck the "Enable SSL verification". (attached image)
- Don't forget to click on the Apply button.enter image description here
That made the trick and Anaconda loads very fast!
I stumbled upon this problem in two pc which had I5 / I7 processor(Win 10 / Win 8) with SSD.
This is how I fixed up the problem, now it takes around 20 second to boot Anaconda Navigator and all the apps) :
Open your prompt / CMD and type :
conda update conda
conda update anaconda
Also looks into your Antivirus :
they may isolate or block Anaconda because they could see it as a threat
Do a tour into your Antivirus/HIP/Firewall/Trusted applications and grant Anaconda full permission
I have one shortcut here,
Go to search bar and type jupyter or if you want spyder
Type spyder , so you can directly open it. No need to start anaconda
Here I saw
https://youtu.be/xNOg5VfCDWU
I started Anaconda Navigator with "Run as Administrator" privileges on my Windows machine, and it worked like a charm. Though it did ask me for Admin credentials for a couple of times while loading different scripts, but the response was <1 min, compared to 6 - 8 mins. earlier.
Search for Anaconda through desktop search or go to Cortana tool on the desktop toolbar and type Anaconda
On the Anaconda icon that shows up, right-click and choose "Run as Administrator"
Provide Admin credentials when prompted
This should hopefully work for Windows 10 users.
I as well had problem of Anaconda Navigator starting after long time ( 5-10 mins) on my Windows 10 machine. After defining proxy settings in .condarc file and OS ENV variable, it reduced to 1-1.5 min. See if it works for you :).
Changes in .condarc file
proxy_servers:
http: http://yourhttpproxy:port
https: https://yourhttpsproxy:port
Updating OS ENV variable like:
HTTP_PROXY= http://yourhttpproxy:port
HTTPS_PROXY = https://yourhttpsproxy:port
*This worked like magic especially if you are using a machine with vpn enabled & proxy
If you know the specific app you are running e.g R, Jupyter e.t.c just simply:
Go to the Windows search button
Type the name e.g Jupyter
Click on it and it opens the notepad!
After encountering the same issue (stucking at loading apps for 6 min), I tried the previous which didn't work. Furthermore, I have also tried to reinstall anaconda without any success.
After a while I tried to tape:"jupyter lab" (or jupyter notebook) on ANACONDA PROMPT. It works for me, now I do not need to start anaconda navigator and then going to jupyter lab or notebook.
Hope it will be helpful for some of you.

Resources