dataprofessor / code

Compilation of R and Python programming codes on the Data Professor YouTube channel.

Home Page:http://youtube.com/dataprofessor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I can't activate my environment in the collab

linda-farias opened this issue · comments

I am in a class work in which I must develop a program in a virtual environment. My choice was '' Google Colab '', but when trying to activate my environment it always gives an error.

! conda create --name metawraptest-env python=3.7.10

WARNING: A conda environment already exists at '/usr/local/envs/metawraptest-env'
Remove existing environment (y/[n])? y

Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /usr/local/envs/metawraptest-env

  added / updated specs:
    - python=3.7.10


The following NEW packages will be INSTALLED:

  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main
  ca-certificates    pkgs/main/linux-64::ca-certificates-2021.4.13-h06a4308_1
  certifi            pkgs/main/linux-64::certifi-2020.12.5-py37h06a4308_0
  ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.33.1-h53a641e_7
  libffi             pkgs/main/linux-64::libffi-3.3-he6710b0_2
  libgcc-ng          pkgs/main/linux-64::libgcc-ng-9.1.0-hdf63c60_0
  libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-9.1.0-hdf63c60_0
  ncurses            pkgs/main/linux-64::ncurses-6.2-he6710b0_1
  openssl            pkgs/main/linux-64::openssl-1.1.1k-h27cfd23_0
  pip                pkgs/main/linux-64::pip-21.0.1-py37h06a4308_0
  python             pkgs/main/linux-64::python-3.7.10-hdb3f193_0
  readline           pkgs/main/linux-64::readline-8.1-h27cfd23_0
  setuptools         pkgs/main/linux-64::setuptools-52.0.0-py37h06a4308_0
  sqlite             pkgs/main/linux-64::sqlite-3.35.4-hdfb4753_0
  tk                 pkgs/main/linux-64::tk-8.6.10-hbc83047_0
  wheel              pkgs/main/noarch::wheel-0.36.2-pyhd3eb1b0_0
  xz                 pkgs/main/linux-64::xz-5.2.5-h7b6447c_0
  zlib               pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3


Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate metawraptest-env
#
# To deactivate an active environment, use
#
#     $ conda deactivate

But, when activating my environment, this appears:
$ conda activate metawraptest-env

File "<ipython-input-45-dbbb19337d51>", line 1
    $ conda activate metawraptest-env
    ^
SyntaxError: invalid syntax

Or this from here:
! conda activate metawraptest-env

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

I tried to use '' Shell '', but it also gave error when using
$ conda init <SHELL_NAME>

 File "<ipython-input-46-248a41531067>", line 1
    $ conda init <SHELL_NAME>
    ^
SyntaxError: invalid syntax

The environment was created, but I can't activate it...
! conda env list

# conda environments:
#
base                  *  /usr/local
metawraptest-env         /usr/local/envs/metawraptest-env

@linda-farias I believe you're trying to activate with $ in the command.
It should be: conda activate metawraptest-env

I'm writing exactly that, but he doesn't recognize that command.

From what your shell reads, you have typed in $ in the command.

Taking it off should work fine

I found that on Google Colab the correct command is: ! activate + name. Then activated

Example:
! activate metawrap-env

Thank you so much!!

Hello, I have used this command

!activate alphapose
!conda env list

But it still don't change the environment in my google colab.

image

the same here
image

this helped me
!conda env update -n base -f environment.yaml
the new environment is generated and activated

this helped me !conda env update -n base -f environment.yaml the new environment is generated and activated

Just to inform, it doesn't work for me (env-dev.yml is my file)
github

Seems like Colab is only able to use env only inside one code block.
So use it like this: !conda activate myenv && call myscript

commented
  1. As someone mentioned previously, "it seems like Colab is only able to use env inside one code block".
  2. Also since Colab won't save your environment every time you shut down the runtime anyway.
  3. I would just install miniconda to get a "clean" environment and install everything in the base env (example notebook).
    !conda env update -n base -f conda-environment.yaml

Hope it would help.

I have a very similar issue. I manage to clone, install conda and create the environment in colab. However I can't activate it, the star (*) sign is not even appearing at all. My notebook is here, perhaps someone can take a look.

https://colab.research.google.com/drive/1rGsVd8rbjFXZzqdIw9LnuEJd3z1sgo7H?usp=sharing

I have tried ($) sign, source command, update the base environment (as advised) but none work. stuck there for a couple of days already. help with any trick?

I have a very similar issue. I manage to clone, install conda and create the environment in colab. However I can't activate it, the star (*) sign is not even appearing at all. My notebook is here, perhaps someone can take a look.

https://colab.research.google.com/drive/1rGsVd8rbjFXZzqdIw9LnuEJd3z1sgo7H?usp=sharing

I have tried ($) sign, source command, update the base environment (as advised) but none work. stuck there for a couple of days already. help with any trick?

%%bash
source activate nilmtk-env
python
import sys
sys.path.append('/usr/local/lib/nilmtk-env/site-packages')
print(sys.path)
print("python version",sys.version)

@guccang did these lines worked for you? Did you try to update the colab notebook? I am trying to confirm after the installation using the line import nilmtk as ntk that currently work on my laptop (I did create this environment in anaconda and running the code using jupyter notebook, but takes forever to train my data). Still no luck on my end :(

https://colab.research.google.com/drive/1rGsVd8rbjFXZzqdIw9LnuEJd3z1sgo7H?usp=sharing

`%%bash
source activate nilmtk-env
python
import sys
sys.path.append('/usr/local/lib/nilmtk-env/site-packages')
print(sys.path)
print("python version",sys.version`
commented

This works for me.
!source activate myenv && python -m spacy download en_core_web_sm

And you should add " !source activate myenv && " to every command you're going to call

This works!!!

This works for me. !source activate myenv && python -m spacy download en_core_web_sm

And you should add " !source activate myenv && " to every command you're going to call

worked for me too. but how can I run python snippet code directly in colab ?