Version Anaconda 4.8.3
What I cannot do:
I can't activate any environment from powershell.
conda activate base
What I can do:
conda env list
conda create -n xxx conda remove -n xxx
I have tried many solutions, but they turn out to be useless:
conda init powershell
restart powershell
conda activate
conda update -n base conda and redo 1
conda install -n root -c pscondaenvs pscondaenvs
Set-ExecutionPolicy RemoteSigned
Run activate base
The result of running conda activate
You don't need Admin permission.
Once you install Anaconda or Miniconda on Windows, open a Anaconda Powershell Prompt from Start Menu.
Or, If you don't see it there, then assuming you have installed
miniconda3 at path C:\miniconda3\4.9.2, do:
powershell -ExecutionPolicy ByPass -NoExit -Command "& 'C:\miniconda3\4.9.2\shell\condabin\conda-hook.ps1' ; conda activate 'C:\miniconda3\4.9.2' "
Now try:
conda init powershell
and reopen powershell.
Additional note: By default conda will autoactivate itself, when we open terminal. If you prefer not, then disable auto-activation with:
conda config --set auto_activate_base false
Open a Anaconda Powershell Prompt from Start Menu.
Now Try:
conda init powershell
Now restart the powershell, if find some error like this in powershell:
\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:3
Then change the execution policy. Type this code to powershell:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
To find more with execution policy you can visit this link.
Here is my easier solution which works with Anaconda, Miniconda, and even Miniforge:
Open Powershell and browse to condabin folder in your conda installation directory, for example: C:\Users\<username>\anaconda3\condabin
Run ./conda init powershell in that folder, and re-open the powershell.
Please note: If you encountered ps1 cannot be loaded because running scripts is disabled on this system, simply run the Powershell as Administrator and enter the following: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
Restart the Powershell & Enjoy!
When you use Anaconda or Miniconda type in Anacondaprompt:
conda init powershell
In order to activate conda on Powershell, I just executed this command:
C:\Users\<username>\anaconda3\shell\condabin\conda-hook.ps1
Then I could see all environments without needing to restart Powershell.
conda env list
conda activate base
So you need to basically just run the conda-hook.ps1 script.
Encountered the same problem. The trick is to make sure that the environment is included in the PATH variable of Windows Powershell. To view the PATH variables enter the following in the powershell:
$env:Path.split(';')
If the environment you desire doesn't show up in the output list, as in
.....
.....
..../envs/yourEnv/...
.....
run the following command on cmd:
conda init powershell
then restart _Anaconda Powershell,
then:
conda activate yourEnv
Hopefully, now the conda prompt should now show your desired environment.
To solve the problem without changing te security policy on powershell, you need to be on powershell 7. Powershell 7 will let you use a \WindowsPowerShell\profile.ps1 file as startup script with default (restricted) security policy settings. Windows Powershell is by default (on windows 10 at 14-08-2022) version 5.x.
Check your powershell version with
$PSVersionTable
If you're still on powershell 5, install powershell from the windows store. This will install powershell 7 alongside powershell 5. It will probably be called Powershell instead of Windows Powershell. Or if you're not allowed to use the windows store, ask IT to install it for you. Check the version again in the new powershell.
After this, we can follow the answer of prashant:
Open Anaconda prompt and run
conda init powershell
To stop conda starting by default run
conda config --set auto_activate_base false
& 'C:\ProgramData\Miniconda3\shell\condabin\conda-hook.ps1'; conda activate 'C:\ProgramData\Miniconda3'
This is the command found in Anaconda Powershell Prompt (Miniconda3).lnk on my computer.
On my machine, I can enter the environment anywhere by executing these two commands.
Related
I'm using the Platformio IDE terminal within Atom. It defaults to powershell, which works. I'm trying to use Anaconda prompt instead of cmd or powershell. The target of Anaconda Prompt and Anaconda Powershell are respectively:
%windir%\System32\cmd.exe "/K" C:\Users\myname\Anaconda3\Scripts\activate.bat C:\Users\myname\Anaconda3
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\Users\myname\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\Users\myname\Anaconda3' "
The terminal works when mapped to the cmd.exe or powershell.exe. It does not work when I add the rest of the target for the Anaconda prompts. I can run the following once the cmd.exe is open in Atom, and it works:
C:\Users\myname\Anaconda3\Scripts\activate.bat C:\Users\myname\Anaconda3enter
I add this into the Shell Arguments field in settings for Platformio, and it doesn't work. Based on the field description ("Specify some arguments to use when launching the shell"), I thought this would auto execute when opening the terminal. That does not appear to be happening. Anybody know how to use the shell arguments field appropriately or write a path for the Shell Override field that accurately boots up Anaconda Prompt/Anaconda Powershell? Thanks!
Yarn's not recognized as a cmd command.
I tried installing it globally with 'npm install -g yarn' and adding a path variable to "C:\Users[user]\AppData\Roaming\npm\yarn".
Any other suggestions?
First thing first, you should check you have 16+ node.js installed and, you can check it with
node -v
If it's valid,
run the npm config get prefix it'll give you a path CTRL+C this path
Open the start search and type in env and then click "Edit the system environment variables"
Modify the Environment variables
Add the copied path to you PATH as new
After this you should be good, but if the PS is cannot load the Yarn run this command
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Here a few things you can try:
You may need to close and reopen the Powershell windows because newly added environment variables or updates to them are not automatically reflected to already open shell windows.
Check if your path is correct: it normally is C:\Users\endo\AppData\Roaming\npm on my PC, not C:\Users\endo\AppData\Roaming\npm\yarn as you mentioned.
Try running yarn.cmd or yarn.ps1.
Try CMD instead of Powershell, see if it works that way.
I am running some automated Python tests with GitLab-CI on a Windows 10 machine. The GitLab-Runner on the machine used to work with executor = "shell" using the simple Windows shell. This recently stopped working (The docs say support for this shell is depreceated) and the only way to get it work again has been to use the powershell instead with adding shell = "powershell" to our config.toml file. For the tests to run, we need to activate a conda environment. Unfortunately, this seems not to work via the powershell script that GitLab-CI creates for the job.
When I open the powershell manually logged in as the user that is executing the gitlab runner jobs, changing conda environments works. I have run conda init powershell and can change the environment with conda activate myenv. Yet, when I include the following in my gitlab-ci.yml file:
script:
- conda activate myenv
- conda list
the output from conda list confirms that the environment myenv is not activated and instead the base environment is used.
Also trying the absolute path like this
script:
- conda activate C:\Users\myuser\Miniconda3\envs\myenv
- conda list
does not work.
So it seems like I can manually activate the correct conda environment in the powershell, but activating the environment via the powershell script created by GitLab-CI does not work. Is there a fix for this problem? Any help is greatly appreciated.
Looks like gitlab executes each line of the script in a separate subshell. Combine the commands into a single line.
If that doesn't work, most conda commands will accept the name of the environment as parameter -n:
conda list -n myenv
conda install -n myenv PackageName
...
As long as you're just using conda, it shouldn't be necessary to activate the environment.
As it seems to be a problem within powershell but not with cmd, one could use the following in the gitlab-ci yaml:
- cmd '/C' 'conda activate myenv && python myunittests.py'
Conda 4.6.14 over-writes my default PowerShell prompt from:
C:\whatevs\okay>
to:
(env) PS>
but I ideally want what it was previously:
(env) C:\whatevs\okay>
How can I undo this change to my PowerShell prompt? I like knowing what path and Conda environment I'm using whenever I execute a command! Is there a setting I can change?
I know it's possible to modify the PowerShell prompt by editing $profile. However, I want to keep the (env). Is there some quick way to get the current Conda environment so I can include it into a custom path?
Details
The file being modified by conda init is $HOME\Documents\WindowsPowerShell\profile.ps1 who's contents are:
#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "C:\Users\user\Anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion
This is an issue with Conda 4.6.14 and can be resolved by downgrading back to 4.6.12 or upgrade to the (currently) experimental 4.7.
I am trying to use packer to provision awscli on a Windows machine. To install the awscli is use the following PowerShell script:
$download_url = 'https://s3.amazonaws.com/aws-cli/AWSCLI64.msi'
$downloaddestination = 'C:\Program Files\awscli.msi'
$checkpath='C:\Program Files\Amazon\AWSCLI'
if (Test-Path $downloaddestination) {
# // File exists do nothing
} else {
# // File does not exist download it
(New-Object System.Net.WebClient).DownloadFile($download_url, $downloaddestination)
}
$env:SEE_MASK_NOZONECHECKS = 1
Start-Process $downloaddestination /qn -Wait | Out-Null
Start-Sleep -Seconds 60
if (Test-Path $checkpath) {
Write-Host "awscli installed"
} else {
Write-Host "Installation failed"
}
I am unable to install awscli, its getting failed to install the MSI package even though its able to download the packege.
I use Python to install the cli, it makes updating easier too. I normally use cloud formation, cloud formation uses the userdata to invoke a script that is run by powershell.
The script looks like this:
mkdir c:\setup-downloads
cd \setup-downloads
curl https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64.exe --output python-inst.exe
.\python-inst.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
Start-Sleep -s 30
$env:Path += ";C:\Program Files\Python37"
$env:Path += ";C:\Program Files\Python37\Scripts"
pip3 install awscli
Create a directory somewhere mkdir c:\setup-downloads . Change to that directory cd \setup-downloads I then use curl to download python: curl https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64.exe --output python-inst.exe
Then I run the install using quiet mode, and I set it up to install itself into the path, and installed for everyone .\python-inst.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
I wait for this to finish Start-Sleep -s 30 But you need to restart the powershell to actually access python so I run the following to set the environment variables:
$env:Path += ";C:\Program Files\Python37"
$env:Path += ";C:\Program Files\Python37\Scripts"
Now that I have python installed, and the environment variables configured I can install the cli as follows:
pip3 install awscli
If you run aws --version it works
I tried #Jasons answer, calling the PowerShell file from an autoattend syncronusCommand block, however, I could not get pip3 command to be recognised.. setting the python env path inline I felt was a little hacky.
Check out - https://www.python.org/download/releases/2.5/msi/ - which explains that when using an MSI file the - installation can be initiated programmatically.
My PowerShell file now looks like this
Invoke-WebRequest -Uri https://awscli.amazonaws.com/AWSCLIV2.msi -Outfile "C:\aws.msi"
Start-Process -Wait -FilePath msiexec -ArgumentList /i, "c:\aws.msi", /qn
Now I have automated the install of aws cli on windows server.
I would suggest changing the approach and installing aws cli via pip the Python package manager that comes with the default Python installation.
Follow this guide to install Python silently on windows. Then you can just run the command below and it will install the awscli.
pip install awscli
You can use pip on windows, it's easy:
1. download and Install Python 2.7 for Win x64 in Python27 folder (default) [I had trouble with Python3.0 but I may have installed it wrong]
https://www.python.org/downloads/
2. in control panel, system, advanced settings add (ie., "new") to the user or system variable:
PYTHONPATH %PYTHONPATH%;C:\Python27\Lib
3. in control panel, system, advanced settings, edit the system PATH variable and add at the end:
;C:\Python27;C:\Python27\Scripts;C:\Program Files\Amazon\AWSCLI\
4. download the awscli package from
https://s3.amazonaws.com/aws-cli/AWSCLI64.msi
5. now you can run in the Windows DOS Command box: "pip install --upgrade awscli"
6. you can run cli commands in Windows DOS Command box, powershell or powershell ise. First run "aws configure" in powershell or win/dos command box
7. then you can run any CLI or CLI SDK command in powershell ise