Using Spyder with Python 2.7 and Python 3 on Linux - python

I am working on a Python 2.7 program. I am not used to use Spyder, I usually use vanilla Python form the terminal. Since my calculation are quite heavy I would like now to use Spyder just to do the plotting without having to run the whole calculation. Basicly I want to use the Spyder because it keeps the variables in a workspace and because it provides the possibilty of messing around with the plotting without having to run a full calculation every time.
I installed Spyder with
sudo apt install spyder
How should I use this installation to choose whether Python 2.7 or Python 3?
What I tried
I also tried to install Spyder throught pip as suggested here like so
python -m pip install spyder
which is not working. So I forced pip to install a specific version of Spyder with
sudo pip install -Iv spyder==2.3.9
but again there is an issue with dependencies. And even if it had worked, it wouldn't have allowed me to select the version of Python. It would only have installed a version of Spyder that works with Python 2.7.
Changing Python interpreter as suggested here doesn't work either. I tried to specify bin/python as Python interpreted but it doesn't work with the IPython kernel.
Solution
As mentionned below the solution is to use conda and virtual environments for each Python version.

I'm not sure if I got your question right,
but if you are not sure how to change the Python interpreter in Spyder, then take a look into this post: How to change python version in anaconda spyder
If you want to run spyder,
just type spyder into your terminal.
If you want to use multiple versions of python consider to use virtual environments created by virtualenv or conda.
For this, take a look into this article: Conda: Creating a virtual environment
Rgds

Related

Installing Python on macOS

I am new in macOS, and I have a little problem with installing python. I have downloaded from python webpage current version 3.9, and installed it. Now if I open command line, and write command
python3 -V
get result
Python 3.8.2
If I run
sudo python3 -V
I get
Python 3.9.7
How can I change it, I would like to have same version even tough I run it without sudo.
An easy way to keep everything consistent is to use something called a Virtual Environment. Here is a ref:
https://sourabhbajaj.com/mac-setup/Python/virtualenv.html
A few tips:
Create the venv under a folder that will work as the top folder of your new 'Workspace'.
You will need to activate your venv with this command:
source venv/bin/activate
I promise it is much easier than it sounds, and it works great.
If python 3.8.2 still comes up wherever and you don't need it then that means it's obviously still in your system so locate the folder and application somewhere and just deleting it by moving to bin should do the trick, make sure you're deleting the right version of python, do not delete Version 2.7 because macOS needs it to run things
Try pyenv
Managing multiple python version is not easy.
With pyenv, you can install a python version as simple as pyenv install 3.3.6. It's also quite easy to manage multiple python version and to switch version for different terminals.

How to install python3.7.0?

I am running a program on ubuntu that requires python 3.7.0, and I dont know how to install it
I have tried anaconda and created an environment, but it didn't work
I have also tried to install python 3.7.0, but when I do python -V, the version is still the 3.6.2 version.
Very interesting things happen.
When I install python3.7, and changed it as the default interpreter, the terminal won't open anymore. I had to change the default back to 3.6 to get terminal to open.
Anyway, I was able to create a virtual environment using anaconda and it works fine. Thank you all for you help

how can I downgrade from python 3.7 to 3.6 in windows

I'm trying to install tensorflow but python 3.7 does not support that, so I want to get python 3.6 instead without using anaconda.
So any suggestion please ?
I have done this multiple times.
My first tip is use virtual environments. That way you can use python 3.6 for what ever project requires that version of python, and python 3.7 for other projects that need that version.
However on windows these are the best steps:
1.) Uninstall python 3.7 from your computer using command prompt
2.) Double check in your program files folder to see if there are any lingering python 3.7 folders you need to delete. Do not delete any site-packages folders or you will need to reinstall the packages you have deleted.
3.) Go to https://www.python.org/downloads/ and download and install python 3.6 and make sure you add it to your path when installing
4.) Open command prompt and type python -V or simply python and check what version you have installed. If you type just python you can use the command exit() after to exit.
But I suggest starting to use Virtual Environments to avoid this issue or downloading different python versions based on specific library needs.
UPDATE
Regarding the point of not deleting site-packages folders. Some of your packages may not be compatible with lower versions of python. This may not be a huge issue for some people, but it is best to check your most commonly used packages to see their compatible python versions before continuing with the downgrade
Consider using pyenv-win in order to manage your global and (per-project) local Python versions.
However, it only works with the Windows Subsystem for Linux.
This solved it for me. Run the following via anaconda prompt
conda create -n py36 python=3.6
activate py36
Select py36 on Anaconda navigator and launch spyder

How to install Spyder for Python 2 and Python 3 and get Python 3 in my Spyder env?

I have Python 2.7 installed (as default in Windows 7 64bit) and also have Python 3 installed in an environment (called Python3).
I would like to use Spyder as my IDE. I have installed Spyder3 in my Python3 environment, but when I open Spyder 3 (from within my Python 3 env), then it opens Spyder for python 2.7 and not python 3.5 as I would've hoped for.). I don't know why.
I have done TOOLS--Preferences--Python Interpreter -- Use the following Python interpreter: C:\Users\16082834\AppData\Local\Continuum\Anaconda2\envs\Python3\python.exe, but this didn't work either.
Many of us are running multiple python environments; I am sure some of you might have managed to use Spyder for these different environments.
Please tell me how I can get Python 3 using this method.
One possible way is to run activate Python3 and then run pip install Spyder.
So, when you create a new environment with: conda create --name python36 python=3.6 anaconda
This will create an env. called python36 and the package to be installed is anaconda (which basically contains everything you'll need for python).
Be sure that your new env. actually is running the ecorrect python version by doing the following:
activate python environmentwith: active python36
then type: python
this will indicate what python version is running in your env. It turns out, for some reason, my environment was running python2.7 and not 3.6
The cool thing is that anaconda distribution comes with spyder. Just be sure that you run Spyder from within your environment.
So to do this: activate python36
then type: spyder
It will automatically open spyder3 for python3.
My initial issue was therefore that even though i created a python3 environment, it was still running python2.7. But after removing the old python3 environment and creating a new python3 env. and installing the desired libraries/packages it now works perfect.
I have a 2.7 and 3.6 environment which can both be edited with spyder2 and spyder3 IDE

How to install Python libraries under specific environments

I have two Anaconda installations on my computer. The first one is based on Python 2.7 and the other is based on Python 3.4. The default Python version is the 3.4 though. What is more, I can start Python 3.4 either by typing /home/eualin/.bin/anaconda3/bin/python or just python. I can do the same but for Python 2.7 by typing /home/eualin/.bin/anaconda2/bin/python. My problem is that I don't know how to install new libraries under certain environments (either under Python 2.7 or Python 3.4). For example, when I do pip install seaborn the library gets installed under Python 3.4 by default when in fact I want to install it under Python 2.7. Any ideas?
EDIT
This is what I am doing so far: the ~/.bashrc file contains the following two blocks, of which only one is enabled at any given time.
# added by Anaconda 2.1.0 installer
export PATH="/home/eualin/.bin/anaconda2/bin:$PATH"
# added by Anaconda3 2.1.0 installer
#export PATH="/home/eualin/.bin/anaconda3/bin:$PATH"
Depending of which version I want to work, I open the fie, comment the opposite block and do source ~/.bashrc Then, I install the libraries I want to use one by one. But, is this the recommended way?
You don't need multiple anaconda distributions for different python versions. I would suggest keeping only one.
conda basically lets you create environments for your different needs.
conda create -n myenv python=3.3 creates a new environment named myenv, which works with a python3.3 interpreter.
source activate myenv switches to the newly created environment. This basically sets the PATH such that pip, conda, python and other binaries point to the correct environment and interpreter.
conda install pip is the first thing you may want to do. Afterwards you can use pip and conda to install the packages you need.
After activating your environment pip install <mypackage> will point to the right version of pip so no need to worry too much.
You may want to create environments for different python versions or different sets of packages. Of course you can easily switch between those environments using source activate <environment name>.
For more examples and details you may want to have a look at the docs.
Virtualenv seems like the obvious answer here, but I do want to suggest an alternative that we've been using to great effect lately: Fig - this is particularly effective since we use Docker in production as well, but I imagine that using Fig as a replacement for virtualenv would be quite effective regardless of your production environment.
Using virtualenv is your best option as #Dettorer has mentioned.
I found this method of installing and using virtualenv the most useful.
Check it out:
Proper way to install virtualenv

Categories

Resources