bcsharp / pscondaenvs Goto Github PK
View Code? Open in Web Editor NEWImplementation of Conda's activate/deactivate functions in Powershell.
License: MIT License
Implementation of Conda's activate/deactivate functions in Powershell.
License: MIT License
Normally, activating an environment takes around one second. But activating a read-only environment on Windows takes almost half a minute.
When installing Anaconda with Visual Studio Installer, Anaconda is installed to C:\Program Files\Anaconda3
. This directory, including envs
subdirectory, is read-only for the user. The user-writable directory is in ~\.conda\envs
. It is still possible to create environments in C:\Program Files\Anaconda3\envs
using the administrator prompt, and those environments are available to all users.
A quick test shows that the delay is on executing
conda '..checkenv' $shellType $Name
The purpose of this command is to check whether the target environment does actually exist in good standing, before the current environment (if any) is deactivated and the activation of the target environment is attempted. The time is spent on line 168 in Lib\site-packages\conda\cli\activate.ps1
:
conda.install.symlink_conda(prefix, context.root_dir, shell)
The shell
variable is 'cmd.exe' instead of 'powershell.exe' because Lib\site-packages\conda\utils.py
has the definitions for PowerShell commented out. As if somebody started to write it and the changed their mind.
"activate" continues to work for the user that installed anaconda, but not for any other users. The only way I have found to fix is to uninstall and reinstall anaconda.
Im not sure if step 2. conda install is running correctly, see the "block is not recognized..." at the end:
conda install -n base -c pscondaenvs pscondaenvs
Solving environment: done
## Package Plan ##
environment location: C:\ProgramData\Anaconda3
added / updated specs:
- pscondaenvs
The following NEW packages will be INSTALLED:
pscondaenvs: 1.2.4-ha00e74d_0 pscondaenvs
The following packages will be UPDATED:
conda: 4.4.10-py36_0 --> 4.5.0-py36_0
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: \ Use 'activate <envname>' or 'deactivate <envname>' in Powershell to manage the current environment.
done
(base) C:\Windows\system32>block should really be the equivalent of
'block' is not recognized as an internal or external command,
operable program or batch file.
The activate.ps1
script uses conda.exe
to perform some of its tasks. This will fail if conda.exe
is not on the search path (the %PATH%
environment variable). Since it is possible to install Anaconda without adding its search paths to the user's %PATH%, the script should be able to locate conda.exe
even if it is not on the search path.
One possibility could be to inspect the path to the script location and navigate to conda.exe
from there. Typically, conda.exe
is in the same directory as activate.ps1
. On Windows, it is «install dir»\Scripts
. On macOS/Linux it is «install dir»/bin
.
It used to be that -Verbose
parameter passed to the scripts was equivalent of setting temporarily $VerbosePreference
to "Continue" (from the default "SilentlyContinue"). This does not happen anymore.
The scripts now have to handle the parameter explicitly.
I can't activate my environment. It's a fresh installation, where I just installed Miniconda and created a Python 3.7 environment.
The command line speaks for itself (λ
is my Powershell prompt-character).
D:\
λ conda --version
conda 4.5.5
D:\
λ conda info --envs
# conda environments:
#
base * D:\Miniconda3
py37 D:\Miniconda3\envs\py37
D:\
λ activate py37
Cannot write to function prompt because it is read-only or constant.
At D:\Miniconda3\Scripts\activate.ps1:129 char:1
+ function global:prompt
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (prompt:String) [], SessionStateUnauthorizedAccessException
+ FullyQualifiedErrorId : FunctionNotWritable
It used to work, but one of the recent PowerShell Core updates changed the name of variable $IsOSX
to $IsMacOS
, breaking the code.
Following a call to deactivate
, the PATH
environment variable is left blank. This prevents any further calls to activate
(or anything else for that matter). Note: the environment was existing prior to installation of pscondaenvs.
To reproduce:
PS src> conda install -n root -c pscondaenvs pscondaenvs
<...>
The following NEW packages will be INSTALLED:
pscondaenvs: 1.2.2-hbdbce43_0 pscondaenvs
Proceed ([y]/n)? y
Use 'activate <envname>' or 'deactivate <envname>' in Powershell to manage the current environment.
PS src> $env:PATH
<current system path...>
PS src> activate streakgui
(streakgui) PS src> $env:PATH
<slightly modified path...>
(streakgui) PS src> deactivate
Deactivating environment "streakgui..."
PS src> $env:PATH
PS src> conda
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ conda
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (conda:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS src> python
python : The term 'python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS src> explorer
explorer : The term 'explorer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ explorer
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (explorer:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
pscondaenvs version: 1.2.2
Conda version: 4.3.30
Powershell version: 5.1.16299.64
python root version: 3.6.2.final.0
Win 10 home 64bits
When unstalling pscondaenvs
package through conda, the installation fails:
Administrator PS C:\Program Files\Anaconda3> conda install -v -n root -c pscondaenvs pscondaenvs
Fetching package metadata .............
Solving package specifications: .
Package plan for installation in environment C:\Program Files\Anaconda3:
The following NEW packages will be INSTALLED:
pscondaenvs: 1.2.0-ha34a360_0 pscondaenvs
Proceed ([y]/n)?
()
===> LINKING PACKAGE: pscondaenvs::pscondaenvs-1.2.0-ha34a360_0 <===
prefix=C:\Program Files\Anaconda3
source=C:\Program Files\Anaconda3\pkgs\pscondaenvs-1.2.0-ha34a360_0
$ C:\WINDOWS\system32\cmd.exe /c C:\Program Files\Anaconda3\Scripts\.pscondaenvs-post-link.bat
==> cwd: C:\Program Files\Anaconda3\Scripts <==
==> exit code: 255 <==
==> stdout <==
b'The syntax of the command is incorrect.\r\n'
==> stderr <==
b'The syntax of the command is incorrect.\r\n'
An error occurred while installing package 'pscondaenvs::pscondaenvs-1.2.0-ha34a360_0'.
LinkError: post-link script failed for package pscondaenvs::pscondaenvs-1.2.0-ha34a360_0
running your command again with `-v` will provide additional information
location of failed script: C:\Program Files\Anaconda3\Scripts\.pscondaenvs-post-link.bat
==> script messages <==
<None>
Attempting to roll back.
The same error happens when trying to install under cmd
.
The problem is on line 5:
set /p VAR=<tmp_stdout.txt
which the cmd shell sees as:
set /p VAR= 0<tmp_stdout.txt
This needs to be done using FOR ... IN ... DO
construct. For instance:
FOR /F "delims=" %%i IN ('CALL powershell.exe -Command Get-ExecutionPolicy') DO SET var=%%i
I install this by conda installer, but when I trying to remove it, he told me this
'he environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:
[WinError 127] 找不到指定的程序。
'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.