can't get python command in anaconda test drive to work - python

I installed Anaconda using defaults.(i'd post a .png of button i pushed but i don't have the rep for more than two links)
I am following the test drive for Anaconda Test Drive and had a problem with Section #2 - Environments.
Following the provided code I created several environments, switched between them, and then deactivated one.
When i deactivated the environment I went to place where 'conda' is not longer a recognized command.
Anaconda Terminal Session:
i open anaconda terminal and begin in the root directory.
i successfully activate the environment 'snowflakes'.
i issue command 'deactivate' which should return me to root directory.
however, i am now farther up the file structure where 'conda' is not a recognized command. i suppose i can issue 'cd appdata\local\continuum\anaconda2' to solve the problem but i'm thinking i've probably messed something up and would like to fix the problem.
any suggestions what to do?
some things i encountered before posting question:
1. when i installed anaconda there was a checkbox that had something to do with PATH - but anaconda encouraged me NOT to check the box - so i did not.
2. I have also read some posts here discussing that one should have a simple path so I wonder if I should install this someplace other than the default path - which is kinda long as you can see in the terminal session.
any help would be appreciated.

I think I know why the command conda is not being recognized.
When you typed the first time (in your screenshot of the terminal) you were at C:\Users\RAdams.GNSMEM\AppData\Local\Continuum\Anaconda2. Inside this folder you should have the executable conda, so when you called it inside this folder makes sense that it may be executed. However, when you called conda outside of this folder (the second time in your screenshot) you had no executable file named conda to be executed. If you wanted to call the command conda without the need of being in the Anaconda2 folder, you should have made this command be inside your PATH variable. Probably that's what the install manager asked you to do and you refused (maybe it recommended you against it because you're dealing with Windows and it may be somewhat different from what happens in Linux).
EDIT:
After taking another look at your screenshot, I saw that the C:\Users\RAdams.GNSMEM\AppData\Local\Continuum\Anaconda2 was, in fact, your environment. You activated this environment and was in the folder C:\Users\RAdams.GNSMEM. Being in this environment makes you able to call the executable files within it even when outside of it. The thing is that you activated snowflakes (and I think that the other environment was automatically deactivated) after that and then deactivated it. So you had no environments loaded when you called conda the last time. Your environments are pretty OK, I guess.

Related

Conda environment defaults to Python 2 even though Python 3 specified during creation [duplicate]

I am using VSCodes terminal pane. I activate a conda environment. For some reason, the python command is still set to /usr/bin/python, instead of the correct path to the conda environment.
% conda activate myenv
% which python
/usr/bin/python
The correct anaconda environment directory does seem to be in the $PATH variable, but /usr/bin seems above it in priority.
When I open a standard terminal through the OS, the behavior is as I expect.
% conda activate myenv
% which python
/Users/cpl/anaconda3/envs/myenv/bin/python
Please note: I have already set the VSCode preferences key python.pythonPath to /Users/cpl/anaconda3/envs/myenv/bin/python, and I think that it works correctly. When I run a file through right-clicking and selecting Run Python File In Terminal, the correct python (from the conda environment) is executed. My problem is using the VSCode terminal directly to execute python.
My shell is zsh, and I am using OSX. Any advice?
This behavior is explained in the VSCode docs:
Why are there duplicate paths in the terminal's $PATH environment variable and/or why are they reversed?#
It sounds like VSCode will run your .zshrc twice in MacOS, conflicting with the conda-generated PATH variable definitions.
There are two solutions listed in the link above. The one that works for me is to set the VSCode setting "terminal.integrated.inheritEnv": false. The documentation warns that all of your environmental variables will be stripped if you do this. However, I find I still have my custom variables defined in the .zshrc file.
It is worth noting that recent versions of VSCode will prompt you when it detects you are using a conda environment, and suggests making this change.
I don't use zsh, but I've run into this issue in bash and I believe the cause is the same.
Conda has recently changed the "official" method of activating environments, as described in this issue: https://github.com/Microsoft/vscode-python/issues/1882
Before, you needed to modify your .bashrc/.zshrc to prepend PATH with the directory of conda's activate script, and then activate specific environments by typing source activate name_of_env. VSCode-Python activates conda terminals by sending this command to the shell — with visible echo, like you typed it yourself.
The new method is to source $HOME/anaconda3/etc/profile.d/conda.sh in .bashrc and then activate environments with conda activate name_of_env, which is the behavior you're seeing work correctly in a dedicated terminal. VSCode-Python does not yet support this, and there appear to be issues with cross-platform support on Windows that are complicating the transition.
The best solution for now is to ignore the "correct" method of conda activate and consistently use the older source activate name_of_env, which still works (if your PATH is set to include $HOME/anaconda3/bin).
A dark magic below may work:-
In my Big Sur, I added the following empty entry to my settings.json -- can be found at File(Windows)/Code(Mac)>Preferences>Settings -- click on any link stated "Edit in settings.json"
"terminal.integrated.env.osx": {
"PATH": ""
}
All the best!
If anyone else in the future ends up scratching their heads over this particular problem, I’ve found another culprit:
Terminal>Integrated>Env: Enable Persistent Sessions
I suspect what happens is that after you update system paths, VScode caches the old path in the terminal and persists it. In this case it persists the old python path rather than the new conda one.
Toggling this option off and restarting VSCode clears that cache, and the new path is loaded in. You can also toggle the option back on after you’re done.

How do I access my conda packages in VS Code?

I am using VS Code for the first time, trying to run a .py file. However it is struggling to find the packages I have in conda (no virtual env, just base).
I have changed the Python interpreter so that it's now using "...64-bit (conda)".
I have also added "python.defaultInterpreterPath": "C:\\Users\\username\\anaconda3\\python.exe" into the JSON settings.
When I then run the file, it finds some packages but not all: it finds os, random and collections but not any others...
Also when I run print(sys.executable) I get "C:\Users\username\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe". I think this should instead be pointing towards the python.exe in anaconda3...
Any assistance with accessing my packages in conda would be appreciated!
As always, read the docs:
https://code.visualstudio.com/docs/python/environments#_create-a-conda-environment
It contains several hints of what can go wrong with conda environments in VSCode.
Most important for you:
A conda environment has to activated before you can use it and obviously this is not happening in your case. The terminal must show a (base) or (Anaconda3) on the prompt. Just pointing to the python.exe is not good enough.
"python.defaultInterpreterPath" only works when you first open your workspace. After you changed it, it will be stored in the database.
You need to make sure you have switched the python interpreter to which you want to use. It would be like this:

i am unable to run pip

before describing my problem i would like to also mention that while the first time intallation i did not check the path option that appears and neither did i check the option for environment variable.
what the problem is :
when i try to give any pip command in my command prompt it says that
pip is not a recognized internal or external command"
when i tried giving a py command it said
can't find a default python
pip files are missing from the script folder
what I have tried
i have tried reinstalling and checking all the checkboxes that are available in the modifier
(result: i ended up at the point i started)
i have tried using the repair option and then using the modify option. still to no avail.
i have tried copying the bootstrap of pip, converted into .py form and moving it to scripts folder.
i have tried using the command py -m pip install
i referred to the help available on the official site
what i need
i need the complete instruction as detailed as possible to what i can do to correct the horrible horrible mistake i have made.
Looks like your Python installation along with pip are not correctly configured in the PATH environment variable.
Firstly, you should find the paths for both installations.
If you haven't changed the default directory while installing Python, the paths should look like in the example below. First one is the directory with python.exe, and the Scripts directory is the one where pip.exe is present.
C:\Users\yourusername\AppData\Local\Programs\Python\Python39
C:\Users\yourusername\AppData\Local\Programs\Python\Python39\Scripts
Secondly, you should edit the PATH variable by adding those found paths to it.
Type "Edit environment variables for your account" in search, and open it.
System properties windows shall open, after that click the Environment variables... button located at the lower right corner. Next, in the User variables for user at the top part of the window, select Path and then click Edit....
In the newly opened window, click the button labeled New and then add both of the previously found paths.
This is how it should look at the end.
After you have added the paths, you are done. Restart your code editor or you may restart your PC to be sure.

Virtual Environment calling global installation of Python instead of venv-specifc version

I'm having an issue where for some reason the virtual environments that I'm creating are accessing my system-wide installations of Python and pip when they shouldn't be.
Here's my fairly simple workflow just make sure I'm not missing anything obvious (Windows 10, Python 3.8.2):
python -m venv venv
venv\Scripts\activate.bat
My path is now prepended by (venv), as you'd expect. However,
pip list
lists all of the system-wide pip packages I have instead of just the ones that should be in that venv.
pyvenv.cfg indicates that
include-system-site-packages = false
When I open the interpreter using
python
In the virtual environment,
sys.executable
Returns the path on my C drive and
print(pip.__file__)
Does the same. I suspect they should instead be pointing to the interpreter and pip in the virtual environment but don't know how to make that happen.
Edit: 4/27/20, Still dealing with this issue, I have tried:
uninstalling and reinstalling Python, both from python.org and the MS Store
Installing python in a new location
Clearing my user and system environment variables and then adding in
just the ones for Python 3.8.
I'm really at a loss here, would appreciate any help.
To anyone looking at this later on, I eventually realized that the problem was only occurring in a specific folder. Making virtual environments elsewhere on my computer seems to work fine. Why this is the case? I have no idea. I'm curious, but not enough to spend another second on this problem. So there you go.
This happened to me too. My problem was that I created the virtual environment under the directory including the global executable (I mean C:\Program Files\Python39). Once I removed this virtual environment and created a new one somewhere else (for example C:\Python), running python command took the executable in the virtual environment rather than the global one.
I had the same problem too. It might be that the path to your virtual environment has a character with accent in it. This basically means that you will have to alter the \Scripts\activate.bat file.
In order to see if that's the case, use the following procedure:
Activate the virtual environment by running the file \Scrips\activate.bat
Run the following command:
echo %PATH%
There should appear a bunch of paths, being path\to\your\virtual\environment\Scripts the first of them (this is obligatory). Check if this path is exactly the same as it is supposed to be (meaning it should have no "strange" characters instead of characters with accents).
If there are any discrepancies, I suggest you alter your \Scripts\activate.bat according to https://stackoverflow.com/a/22348546/11923771, reopen your Command Prompt and follow steps 1 and 2 again to see if your problem was solved.

Can't set virtualenv - problem with source activation.ps1

Fallowing the freecodecamp's django tutorial I'm stack on the very beginning - I can't set up virtualenv. Everything goes great until it's time to make final step - activate virtualenv and download Django.
I'm working on Windows 10, and tried a lot of ways to solve it. Everything ends up with to results, but first things first. Here is what i did:
Ran powershell as administrator and set up ExecutionsPolicy as unrestricted
Create new folder called 'Dev'
Inside Dev created another folder for project with virtualenv - everything by command 'virtualenv name of the folder
Tried to activate it by "name_of_project's_folder\Scripts\activate"
After this I'm getting error which says that I must "source this script". I tried to make path to the Scripts folder and type only activate but it doesn't work. When I tried to type "name_of_project's_folder\Scripts\activate" but with ".bat" added on the end, nothing happens. Like, literally nothing.
I really hope for making this work because I'm slowly getting frustrated coz of tons of research I made today nad a lot of blind tries to solve this. Python was downloaded via powershell and pip if it's important.
What about project_folder\Scripts\activate.ps1? Or you can just use cmd instead of powershell.

Categories