Windows Subsystem for Linux - conda: command not found - python

I'm using Windows 10 and recently installed Windows Subsystem for Linux.
Anaconda was already installed on my PC at that point.
When I try to run conda commands on Bash on Ubuntu on Windows I get the following error:
$ conda conda: command not found
Other related answers, such as this or this suggest adding
C:\Users\«user»\Anaconda3\Scripts
C:\Users\«user»\Anaconda3
to $PATH. But as you can see below, both are already included (I didn't add them manually):
$ echo $PATH | tr ':' '\n'
...
/mnt/c/Users/«user»/Anaconda3
/mnt/c/Users/«user»/Anaconda3/Scripts
/mnt/c/Users/«user»/Anaconda3/Library/bin
...
The following conda files are available in Anaconda3/Scripts:
conda.exe
conda-env.exe
conda-env-script.py
conda-script.py
conda-server.exe
conda-server-script.py
The commands work just fine in both PowerShell and cmd.
What am I missing?
[EDIT]: Corrected second URL and changed user to < user > in Anaconda3 paths above.

Try to run conda.exe instead of conda.
Windows assume .exe marks a file as executable, and ignores that extension when looking for the binary. Linux uses a flag, so any file can be an executable, and you need to provide the full name because there is no assumption on the extension.

Run conda init
.anaconda3/bin/conda init
.miniconda/bin/conda init

To add conda to Windows Subsystem Linux, this is the correct way:
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
export PATH=$PATH:/miniconda3/bin
You will need to restart WSL for the env path to work.

Related

Poetry installation with Windows WSL not working, ignoring $HOME

I have a WSL instance, Ubuntu 20.04 and I have created another Ubuntu 18.04 WSL instance.
I installed Poetry on the 20.04 without issues.
I am trying to install Poetry on the Ubuntu 18.04 instance, using the curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 - command.
At the moment, my $HOME env var points to /home/fromzeroedu.
However, after installation, Poetry is installed on my Windows user home:
$ which poetry
/mnt/c/Users/j/.poetry/bin/poetry
And if I try getting the version, I get:
$ poetry --version
/usr/bin/env: ‘python\r’: Permission denied
I even tried setting the POETRY_HOME prior to installation:
export POETRY_HOME=/home/fromzeroedu/.poetry/bin/poetry
But Poetry still installs in the Windows user directory.
Sometimes I love Poetry...
That was because bash didn't knew where to look for the bin so it found only the Windows executable (PATH is shared between wsl and windows)
to solve it you needed to add the following to your ~/.bashrc (preferably on top)
export PATH="$HOME/.poetry/bin:$PATH"
With the new installer (poetry 1.1.7 onward) the Bin path changed
export PATH="$HOME/.local/bin:$PATH"
I faced this issue cause I'm using autocomplete plugin for oh-my-zsh and poetry needs to be added to PATH before the plugin is loaded. but the installation script append it at the end.

Conda command working in command prompt but not in bash script

my anaconda (4.5.4) works fine as long as I just use it via a linux terminal (bash shell). However, running conda commands in a bash script does not work at all.
The script test.sh containes these lines:
#!/bin/bash
conda --version
conda activate env
Now, running bash test.sh results in the error
test.sh: line 2: conda: command not found
test.sh: line 3: conda: command not found
As recommended for anaconda version > 4.4 my .bashrc does not contain
export PATH="/opt/anaconda/bin:$PATH",
but
. /opt/anaconda/etc/profile.d/conda.sh
Thank you.
I solved the problem thanks to #darthbith 's comment.
Since conda is a bash function and bash functions can not be propagated to independent shells (e.g. opened by executing a bash script), one has to add the line
source /opt/anaconda/etc/profile.d/conda.sh
to the bash script before calling conda commands. Otherwise bash will not know about conda.
If #randomwalker's method doesn't work for you, which it won't any time your script is run in a more basic shell such as sh, then you have two options.
Add this to your script: eval $(conda shell.bash hook)
Call your script with: bash -i <scriptname> so that it runs in your interactive environment.
Let's say you try to access user name with "miky" # "server" address.First when you login to your user ; learn conda path with "which conda" then probably you will get a path such as "/home/miky/anaconda3/bin/conda"
then put your conda commands as follow (in my example i use conda to install a mysql plugin forexample.): shh miky#server -t "/home/miky/anaconda3/bin/conda install -y -c anaconda mysql-connector-python" thats all.
do sudo ln -s /home/<user>/miniconda3/etc/profile.d/conda.sh /etc/profile.d/conda.sh and try again. This should activate conda for all users permenantly
source

How can I access the vim installed with the anaconda prompt?

I've started the Anaconda python distribution. This comes with something called
'Anaconda prompt' that has conda and git available at the Windows command line.
When I make a commit from this command line, Vim comes up as the editor.
When I type 'vim' or 'vi' at this prompt I get the message:
'vim' is not recognized as an internal or external command, operable
program or batch file.
How can I access vim from the Anaconda prompt?
I was facing the same issue while using vim or vi commands because the package was not installed on my machine. To use the vim command of anaconda prompt with windows os, then use this given command ' conda install -c conda-forge vim '. This command will install the required dependencies and then just simply use the vim command example - vim file_name.
Reference
I am on a mac, but have been using the anaconda prompt on my Windows work machine. You need to add the path of the vim tool to the Windows path environmental variable. I set mine up to use notepad++ when I did a recent install. You can probably find vim in the %APPDATA% directory where anaconda is located if you installed it under the user and not the system. If you search for vim there, you might fine it. If it isn't there it might have gotten installed with another tool.
Install PyVim instead as below and open your textual files in your Anaconda Prompt:
pip install pyvim

<pip3 package> command not found on zsh but found on bash

I installed django on my Ubuntu 16.04 using pip3 install django. But when I type django-admin and hit enter I get command not found. I even verified using:
import django
print(django.get_version())
I use zshell instead of bash. At first I thought this is a django issue. So I installed another pip3 package virtualenv. I then typed virtualenv on terminal and hit enter, same output: command not found.
Then I was sure this is a shell issue. So I changed my shell back to bash and both django-admin and virtuaenv commands were found.
How can I get zsh to discover the pip3 packages?
As you have mentioned, your Python package executables are installed to ~/.local/bin. If you check $PATH in bash, you will find it contains that path. In the default Ubuntu 16.04 installation, this is done in ~/.profile. zsh does not execute this file, however, and so probably does not have ~/.local/bin in its $PATH. The solution as you have found is to add it: this can be done automatically by modifying your .zshrc, e.g.
export PATH=$HOME/.local/bin:$PATH

Install Anaconda on Ubuntu (or Linux) via command line

I would like to install Anaconda on a remote server.
The server is running Ubuntu 12.04.
I only have access to this server via SSH.
How can I install Anaconda via the command line?
Something along the lines of:
wget https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh
to get the installer for 64 bit linux followed by:
bash Anaconda3-2020.07-Linux-x86_64.sh
You can get the latest release from here
Please take a look at the Anaconda repo archive page and select an appropriate version that you'd like to install.
After that, just do:
# replace this `Anaconda3-version.num-Linux-x86_64.sh` with your choice
~$ wget -c https://repo.continuum.io/archive/Anaconda3-vers.num-Linux-x86_64.sh
~$ bash Anaconda3-version.num-Linux-x86_64.sh
Concrete Example:
As of this writing, Anaconda3-2020.07 is the latest version. So,
~$ wget -c https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh
~$ bash Anaconda3-2020.07-Linux-x86_64.sh
P.S. Based on comments, this should also work in CentOS systems.
You can do as Prashant said or you can use bash scripts to automate the installation. Just simply copy and paste depending on the version of Python you want
If you are trying to it entirely in command line you use a bash script
python 2 anaconda install bash script:
# Go to home directory
cd ~
# You can change what anaconda version you want at
# https://repo.continuum.io/archive/
wget https://repo.continuum.io/archive/Anaconda2-4.2.0-Linux-x86_64.sh
bash Anaconda2-4.2.0-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda2-4.2.0-Linux-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.bashrc
# Refresh basically
source .bashrc
conda update conda
python 3 anaconda install bash script
# Go to home directory
cd ~
# You can change what anaconda version you want at
# https://repo.continuum.io/archive/
wget https://repo.continuum.io/archive/Anaconda3-4.2.0-Linux-x86_64.sh
bash Anaconda3-4.2.0-Linux-x86_64.sh -b -p ~/anaconda
rm Anaconda3-4.2.0-Linux-x86_64.sh
echo 'export PATH="~/anaconda/bin:$PATH"' >> ~/.bashrc
# Refresh basically
source .bashrc
conda update conda
Source: https://medium.com/#GalarnykMichael/install-python-on-ubuntu-anaconda-65623042cb5a
Download Anaconda for linux, place in your ubuntu system through WinScp, then
$ sudo bash Anaconda2-4.3.0-Linux-x86_64.sh
after this logout of your ssh session and then login, you will get base environment.
1 - Go to Anaconda Repository, find the installation for your OS and copy the address
2 - wget {paste}. Ex: https://repo.continuum.io/archive/Anaconda3-5.2.0-Linux-x86_64.sh
3 - Execute with: bash. Ex: bash Anaconda3-5.2.0-Linux-x86_64.sh
Run!
$ sudo bash Anaconda2-4.3.0-Linux-x86_64.sh
Video tutorial::
https://youtu.be/JP60kTsVJ8E
Just download the anaconda installer and execute it as it is a shell script. Follow the steps :
In the terminal type "wget https://repo.continuum.io/archive/Anaconda-2.3.0-Linux-x86_64.sh"
The file will be downloaded in current directory. Now execute the downloaded file by "bash ./Anaconda-2.3.0-Linux-x86_64.sh"
Restart the terminal. This is very important for python version provided by anaconda to be set to default for that user.
Note- Try using environment for using different version of python. Changing the default python version for root might result in non functioning of some functionalities like yum.

Categories

Resources