Collection of Python Environment Issues

PyCharm

Anaconda

Conda

Create a Conda Virtual Environment

  • Specify the Python version and environment name:
    • conda create -n env_name python=3.8
  • Specify the Python version, environment name, and installation path:
    • conda create --prefix=C:/ProgramData/Anaconda3/envs/ENV_spider python=3.9
  • Activate the environment:
    • conda activate env_name
  • Install a package in the currently active environment:
    • conda install package_name
  • Exit the currently active environment:
    • conda deactivate

Pip

Jupyter

Install a Kernel

  • Activate or switch to the virtual environment to add, then check whether ipykernel is installed:
    • python -m ipykernel --version
  • If it is not installed, install it:
    • python -m pip install ipykernel
  • Add the environment as a Jupyter kernel:
    • python -m ipykernel install --name env_name

View Installed Kernels

  • jupyter kernelspec list
(ENV_machinelearning) λ jupyter kernelspec list
Available kernels:
  %s    %s python3             C:\ProgramData\Anaconda3\envs\ENV_machinelearning\share\jupyter\kernels\python3
  %s    %s pycharm-78712231    C:\Users\Jin\AppData\Roaming\jupyter\kernels\pycharm-78712231
  %s    %s pycharm-ae39b4c1    C:\Users\Jin\AppData\Roaming\jupyter\kernels\pycharm-ae39b4c1
  %s    %s env_machinelearning C:\ProgramData\jupyter\kernels\env_machinelearning

Remove a Jupyter Kernel

  • jupyter kernelspec remove kernelname
What do you think?
0 Reactions
Pick a reaction