Anaconda Jupyter Notebooks Kernel Problems - python

TL,DR: How can I make my machine/anaconda forget that python 3.7 exists so that I can run everything on python 3.6?
I've put the full story in a list format to make this easier to read.
1) I have a working BagOfWords in Python 2.7. It was running just fine with Jupyter Notebooks.
2) I wanted to use a python library called Newspaper, but it works best in python 3 instead of python 2.
3) I download python 3.7 so Newspaper can run.
4) Newspaper works great with Python 3.7, but another module, tensorflow, which is necessary for the BagofWords to run, is not yet updated to work with Python 3.7
5) I download Python 3.6, which works with tensorflow.
6) I delete Python 3.7 off my machine.
7) I try to reopen my work now using python 3.6 so tensorflow can work. Jupyter Notebook opens, but prompts me to select which kernel to use. I select Python 3, but I recieve this error message: Error Starting Kernel FileNotFoundError: [Errno 2] No such file or directory: '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3':
8) I know that it is trying to find things though a path that no longer exists (the python 3.7 path). I delete and reinstall anaconda in the hopes that it will forget this old path (and python 3.7) so that I can work with Python 3.6. It does not work.
question: How can I make my machine/anaconda forget that python 3.7 exists so that I can run everything on python 3.6? This is my first time working with jupyter notebooks, so I have searched for answers but many of them did not make sense to me. I am working on a 2015 Macbook Pro that is running MacOs Mojave 10.14.1
Update: even trying new environments with conda didn't work. I eventually gave up and moved all my code to google colab, which I'm not a huge fan of, but at least it actually works....

I would suggest that you just a create a new environment with the specific python version you want (3.6 in your case if you want to use tensorflow)
conda create -n yourenvname python=3.6 anaconda
After creating the environment, activate it:
source activate yourenvname (if on Windows, then: conda activate yourenvname)
Now that you have a balnk new environment you can start installing only the needed packages - tensorflow to begin with using pip.
Any other package you need in this specific environment you can install also using pip or conda install as long as the environment is activated.
Keep in mind though that you need to deactivate the environment if you want to use other versions or other packages for other projects.
Hope this helps.

Related

IDLE and PyCharm are using different versions of python, despite the python.exe PyCharm is using being installed in the same directory

I cloned a python environment and recreated it on a new machine using Anaconda Navigator with a yml file. My script runs fine in the new environment using PyCharm. The python version of this environment is 3.9.0. However the script doesn't run with IDLE because IDLE is running version 3.11.0.
IDLE is located at:
C:\ProgramData\Anaconda3\envs\CloneETL3\Lib\idlelib\idle.pat
The python interpreter which PyCharm uses is located at
C:\ProgramData\Anaconda3\envs\CloneETL3\python.exe
How can IDLE have a different version from the python interpreter when they were just installed fresh? How can I prevent multiple versions of python from running on my machine? I made sure to create a new project in PyCharm, use an existing interpreter using conda and point it to the exe I described above.
The environment was first created from a clone of my ArcGIS Pro environment.
Thanks for the help!
This is quite common in most editors. I use vscode which is similar to pycharm and the user can select the version of python (or other languages) that they wish to run.
It look like this:
The reason for this is that some users have the requirement of being compatible with previous versions. You should be able to select the latest version of each.
Alternatively you can delete all versions leaving only the one version that you desire, this would avoid confusion...
You could refer to this answer for that option: How to completely remove Python from a Windows machine?

zsh: commands not working for pip, conda, python

So here is my story:
As we know macos comes with pyhton 2.7 preinstalled. Years ago, I installed python 3.7.0 and all going good. I started working with Tensorflow and during that time tensorflow wasn't compatible with 3.7.0 so switch the version to 3.6.6 somehow :). After some time i installed anaconda and it installed 3.7.3.
At this point:
When i open my python IDLE shell, it runs on 3.6.6
anaconda Jupiter notebook shows 3.7.3.
Then i learned to create virtual environments through terminal and i use following code to create virtual environment:
pip install virtualenv
virtualenv project_env
And after i activate the virtual environment the python version it shows is 3.7.3.
Then recently i changed the terminal shell to zsh and now everything is kind of messed up. I'm
Terminal can't find conda commands. How to fix that?
Now i can't create virtual environment through virtualenv project_env. It says command not found. Why? It use to create virtual environments with python 3.7.3.
Now to create virtual environment i use python3 -m venv project_env this creates the virtual environment with python 3.6.6. If i use python3.7 -m venv project_env it creates environment with python 3.7.0.
I can't find a way to create virtual environments with python 3.7.3.
I need help with above troubles caused after installing zsh and help with accessing python versions wherever i need. How do i update python version 3.7.0 to latest or any specific version like 3.7.3. Hows python 3.8.4 to use, i mean like i had trouble importing tensorflow in python 3.7.0.
I hope you will understand my trouble and searched a lot for solutions. I'm so confused right now, couldn't even figure out the title of my problem.
Based on the fact your shell can't find conda now, you should look at your "path" environment variable. Whenever you change from one shell to another, you need to look at and possible create or modify the files the shell uses upon startup. These files setup your environment (PATH, PYTHONPATH, etc), create aliases, etc. You may need to create the .zshrc, .zprofile, .zlogin etc files and add the same settings as your previous shell's startup files.
Example:
If you used the bash shell previously you would need to modify the .zshrc file to include your settings in the .bashrc file. Syntax may be different, so a straight copy may or may not work.
Try this as a quick temporary fix (may or may not work, depending on your current ~/.profile settings:
Create a ~/.zprofile file with this code inside:
emulate sh
. ~/.profile
emulate zsh
references:
https://superuser.com/questions/187639/zsh-not-hitting-profile
http://zsh.sourceforge.net/Intro/intro_3.html

How I can delete python 3.4 if i use just anaconda python

I have a specific problem with python. I have on my ubuntu two versions python3.4 and python3.6(from anaconda). I want use just anaconda pythoncurrent version
But when i run script i have some problems with another python version
another version
How i can safe delete useless python 3.4.6?
sudo apt-get remove python3.4
anaconda should have set python3 as default python3.6 version
You should probably not delete Python3 from your system, even if you have Anaconda installed, since there might be system software that:
was not tested with subsequent versions of Python;
might struggle finding Python from Anaconda.
What you should do instead is configure your IDE / environment to run Python script with Anaconda, e.g. by setting your PATH variable to point to your anaconda/bin directory or similar.
If you are using PyCharm, as it seems from the screenshot, you could set up your project to run the Anaconda Python without modifying your other command-line settings.

Jupyter (iPython) notebook says "cannot find a kernel matching Python [Root]"

I'm interested in using Jupyter notebooks with both Python 2 and Python 3 (one of my colleagues insists on still using Python 2 ;) ).
So I diligently followed the steps listed in this excellent answer: Using both Python 2.x and Python 3.x in IPython Notebook.
I installed multiple kernels and now Jupyter notebooks has the option to use both Python 2 and Python 3!
However, I managed to somehow delete the Python[Root] kernel. Now, every time I open a notebook, it comes up with an error message and makes me choose between Python 2 and Python 3 kernel.
This is not the end of the world, but I'd like it to default to my Python[Root] kernel every time I open a new notebook. I use Anaconda by the way.
Thanks for the assistance!
The following assumes you've already created a python3 venv and you're using a windows system:
Open the command line and activate the python3 environment with:
activate <environment name>
On the same command line of step 1, install jupyter for python3:
pip install jupyter
Create a bat file on the folder containing the python3 notebooks:
jupyter.bat:
c:\<anaconda path>\envs\<environment name>\Scripts\jupyter-notebook.exe
Now just run jupyter.bat and it should open the default browser with all the python3 notebooks on the current folder.
I have not had time to fully digest the answer in the post you reference: Using both Python 2.x and Python 3.x in IPython Notebook -- but if what you currently have isn't working properly then what I would suggest is:
Install Anaconda if you haven't already (it sounds like you probably have done this).
conda update conda to update to the latest Conda (always a good idea)
conda install anaconda=4.1.1 to make sure you have the latest Anaconda (well, as of this date)
conda create -n ana41py27 anaconda python=2.7 to create a Python 2.7 based Conda environment that contains all the Anaconda packages
conda create -n ana41py35 anaconda python=3.5 to create a Python 3.5 based Conda environment that contains all the Anaconda packages
If you have any problems with those steps, report them here or on the Anaconda mailing list.
Once you have that in place you can start Jupyter notebook (any way you like, pretty much), and then you will be able to create new notebooks that are either Python 2.7 or Python 3.5 based by choosing the appropriate kernel from the "New" button:
or change between a Python 2.7 or Python 3.5 kernel from within a Notebook:

Running different kernels (e.g. Python 2.7) on Juypter

I have Python 2.7.10 (which I just installed) and I recently installed Jupyter. However the only kind of notebook I can create when I open Jupyter is iTorch and Python 3.
How can I create a notebook in Python 2.7?
I'm attempting to complete a TensorFlow tutorial and that is written in Python 2.7.
The best way to run multiple versions of Python is with virtual environments. Then you can run whatever version you like whenever you like. A great way to do this for people who don't want to spend a lot of time working on it (like me) is with Continuum's Anaconda distribution of Python. I couldn't get the hang of virtual environments till this came along.
Before going any further, I recommend uninstalling the Python 2.7 you installed, and reverting to your system's Python as far as possible.
Then install Anaconda. Install the Python 3.5 version since you'll want to use that most of the time. Almost all libraries I use support it now. Google App Engine and TensorFlow are the only things I use that don't.
Now you should be able to create a Python 2.7 environment like so:
conda create -n python2 python=2.7 anaconda
The python2 is just the name; call it whatever you like. The anaconda bit installs the scientific Python stack; you can leave that off if you want a very basic environment.
Creating the environment doesn't start it. Start the environment with:
source activate python2
Add it to the notebook with:
ipython kernelspec install-self --user
Now install TensorFlow using whichever command Google recommends for your system.
Whenever you want to use that environment, do the source activate command again. To leave it, start another environment or type source deactivate. You can make as many environments as you like, with whatever versions of Python and whatever other packages you want.
Read more about managing environments.

Categories