Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I can't activate my environment in the collab #10

Open
linda-farias opened this issue May 2, 2021 · 17 comments
Open

I can't activate my environment in the collab #10

linda-farias opened this issue May 2, 2021 · 17 comments

Comments

@linda-farias
Copy link

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
@RajathPrabhu221
Copy link

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

@linda-farias
Copy link
Author

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

@RajathPrabhu221
Copy link

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

Taking it off should work fine

@linda-farias
Copy link
Author

linda-farias commented May 14, 2021

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

Example:
! activate metawrap-env

Thank you so much!!

@dekathomas
Copy link

Hello, I have used this command

!activate alphapose
!conda env list

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

image

@1feres1
Copy link

1feres1 commented Feb 22, 2022

the same here
image

@1feres1
Copy link

1feres1 commented Feb 22, 2022

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

@Ferx2226
Copy link

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

@iVoider
Copy link

iVoider commented Sep 20, 2022

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

@Nov05
Copy link

Nov05 commented Mar 7, 2023

  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.

@ccruzalegui
Copy link

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?

@guccang
Copy link

guccang commented Apr 13, 2023

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)

@ccruzalegui
Copy link

ccruzalegui commented Apr 13, 2023

@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`

@yeeyou
Copy link

yeeyou commented May 31, 2023

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

@zxers
Copy link

zxers commented Sep 13, 2023

This works!!!

@efanhome
Copy link

efanhome commented Jan 4, 2024

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests