Virtual Environment in Terminal PyCharm not Working. If run through PyCharm it works, but the terminal uses the base interpreter
I removed the virtual environment and reinstalled
Related
Installation:
I'm a newbie in Python and I'm facing issues with Anaconda. Whenever I launch Anaconda Navigator it shows Python stopped working and crashes.
Also if I type python in the command prompt I get a warning:
"Python interpreter is in a conda environment, but the environment has not been activated. Libraries may fail to load. To activate this environment please see https://conda.io/activation"
I have seen such questions before and tried the solutions, but nothing seems to work. I also tried to reinstall, but it's the same every time.
Try:
conda activate base
Or create a venv:
conda create my_env
conda activate my_env
Or install the Python system directly. Download from here.
This seems to be two separate issues:
Crashing on Anaconda Navigator startup
Try to update PyQt. For more information, see: Spyder and Anaconda Navigator do not open - "Python has stopped working" (Fixed) #10088
For the Python commands, try to activate your environment: conda activate base.
I opened an existing project with pycharm, then I switched the python interpreter to a conda environment I havd created in terminal: cc_env_python3.7
Then I opened the terminal console in pyCharm, one can see that the conda environment is now activated:
However, the default python in this conda environment is still the local python:
The problem only exist in the pyCharm shell, when I activate the conda environment with Terminal, everything works fine.
How can I open a pyCharm shell with default python assigned correctly?
I created and activated a virtual environment with virtualenv:
virtualenv venv
source venv/bin/activate
Then I installed spyder kernels and other libraries in the virtual environment:
pip install spyder-kernels==0.*
pip install numba==0.50
Then I launched Spyder in the virtual environment:
spyder
And I changed the python interpreter in Spyder to the correct path using: > Python > Preferences > Python interpreter > Use the following Python interpreter.
My Python interpreter in my virtual environment is
/Users/myname/venv/bin/python
I also restarted the Spyder console several times.
However, when I import libraries in Spyder, rather than the libraries installed in the virtual environment, Spyder uses the libraries from the base Anaconda environment.
import numba
print(numba.__version__)
0.38.0
print(numba.__file__)
/anaconda3/lib/python3.6/site-packages/numba/__init__.py
This is causing all kinds of errors in my code.
What can I do to force Spyder to only use libraries installed in my virtual environment?
P.S: My Spyder version is 3.2.8, and Python is 3.6.6.
I reinstalled the most recent version of Anaconda from here, which came with Spyder 4.0.1 and Python 3.7.6. That alone solved the problem for me.
I am running Pycharm 2019.3 on Linux Ubuntu 18.04 LTS. I have created a virtual environment for my Pycharm project from within the IDE. I am able to access the packages from the virtual environment when I run programs from within the IDE. However, if I activate the virtual environment created from within Pycharm from the terminal (using source venv/bin/activate, resulting in the (venv) prefix on the command line), the packages I added to the virtual environment can no longer be found. Why is this? The (venv) prefix makes me think that I have successfully activated the virtual environment. What can I do to use this virtual environment outside of Pycharm?
I think this is because pycharm has created a virtual environment in a different location. I think you can check both the locations with echo $VIRTUAL_ENV and check if they are the same.
I created a new project in PyCharm and I made an environment file for the project. I want to use Jupyter Notebook with that project now and since Jupyter in PyCharm is not as great, I want to launch it from cmd. I am not able to figure out to activate the environment created in PyCharm from the command line. Can anyone help me with that?
find the location of environment from PyCharm's project's interpreter settings
From the terminal Run:
source /path/to/env-activate
Solution For Linux
try to use pyenv, once you install virtualenv with pyenv for example
cd ~/your_project_root_folder
pyenv install 3.6.1
pyenv virtualenv 3.6.1 your_venv_name
pyenv local your_venv_name
Then whatever shell command is launched (even from pyenv) you will have correct virtualenv and you don't need to change anything inside pycharm
PyENV
https://github.com/pyenv/pyenv-installer