I am running a Python 2.7 script that has specific dependencies/libraries (contained in a virtual environment) using anaconda prompt. Is there a way to run the script using code in a python 3 .py file in a different environment? Something like a library that allows me to open anaconda prompt in a specific environment (to then run the python 2.7 script). I couldn't seem to find it online. Any pointers would be appreciated.
Well you can select the environment from the drop-down box in the Anaconda Navigator home page if you have your virtual environment in Anaconda itself.
Or you can use
conda activate env-name
If you have your base conda in your terminal as default or else activate using
source ~/.bash_profile
then run
conda activate env-name
Hope this helps.
Related
For reference, I'm on Windows 11 using the Bash shell and have Python 3.9.2 installed.
I'm trying to create and activate a Python virtual environment using venv but when I activate it, nothing happens, but no error is given either. My understanding is that once I activate it, my prompt should change to reflect the environment I'm working in, and where python should show it in the virtual environment. Can anyone help clear this up for me?
Bash is unlike the normal command line interfaces on Windows. It uses the shell language, hence you'll not be able to activate it using the same procedure.
Since you generated the file from Windows,
to activate the virtual environment, run:
cd example_venv/Scripts
. activate
Take note of the space after the dot. It's very important for it to be included.
For those using Mac OS or Linux, you can just run:
source <path_to_venv>/bin/activate
where <path_to_venv> is the location of your virtual environment.
I have created a miniconda virtual environment
conda create --name finalenv python=3.6
Now when I activate it:
conda activate finalenv
and check:
python --version
It says:
2.7.16
Even though I created a virtual environment with python 3.6 version. This is in my Visual Studio Code Terminal. How can I fix this?
If I check python --versionoutside the virtual env, it's 3.8.10.
For example, if I try to install a particular library outside the virtual env, it works fine but throws an error if I run the same command inside the virtualenv since over there, the terminal is using an old python version #Samuel
In VScode do the following:
File -> Preferences -> Settings
Search for "python.pythonPath"
Change path to where you usually run python from (where python 3.6.13 is located on your machine)
I have installed anaconda and create and activated an environment with anaconda prompt.
But when I open python with anaconda, whether inside my anaconda folder or inside the environment folder in it, (or even if I open a python file with spider), it seems it is not using anaconda (according to sys.version).
Indeed python tells me "this python is in a conda environment, but the environment has not been activated".
I have already activated my environment in conda prompt, and I had no error message, so I guess it was succesfful. I have also tried to set my path with in conda prompt: set PATH=C:\Anaconda\envs\py33\Scripts;C:\Anaconda\envs\py33;%PATH% (with my right personal path).
Would you know what is happening?
Thank you
picture of my problem
I am trying to change the Interpreter from Python 3.7 to Python 3.6 in Spyder. I have gone to preferences then to Python Interpreter. I click the drop down box but there is nothing there. How do I add Python 3.6 as on option in the drop down?
You are using Spyder then I assume you have installed Anaconda.
Unfortunately tensorflow doesnt work in python 3.7 yet.
To use Tensorflow/Keras: create new environment with python 3.6 and then use them seamlessly.
To create enviroment in conda:
Use anaconda prompt/anaconda navigator for environment management.
In case of Anaconda Prompt, create environments similar to below code
conda create --name env_name python=3.6
then to use this environment just created, do:
activate env_name # on windows
source activate env_name # on mac
Then if you are done with your works in that environment, deactivate the environment using deactivatecommand in prompt.
deactivate # in windows
source deactivate # in mac
For more help on environment management visit this link.
From what I have learnt in the documentation it states that you can easily switch between 2 python environments by just creating a new variable using command prompt
"conda create -n python34 python=3.4 anaconda" if i already have python 2.7 installed.
An environment named python 34 is created and we can activate it using "activate python 34" But all this happens like executing the above commands happens in my windows command prompt. I want to switch between python versions in spyder IDE, How to do this?
Spyder is launched from the environment that you're using.
So if you want to use python 3 in Spyder then you activate python34 (or whatever you named the environment with Python 3) then run spyder.
If you want to use python 2 in Spyder then you deactivate the python3 environment (or activate an environment in which you installed Python 2) then run spyder.
I do not believe that you can change environments once Spyder is launched.
N.B. you may need to install Spyder in each environment, depending on your set up, by first activating the environment then using conda install spyder.
Just go to preferences in spyder & then go to Python interpreter-> Use the following python interpreter: here, from browse files option, give path for your python2.exe file & then apply. Now your python2 doesn't have spyder-kernels module required to open console in spyder so install it by writing command in cmd python2 -m pip install spyder-kernels. Here python2 -m is used coz I have two versions of python installed
Just go to the directory where you have installed Spyder(use cd in command prompt), for me, it looks like "C:\Users\Rohan\Anaconda2" and type spyder in cmd. it will run your Spyder IDE.