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:
Related
I located a really weird behavior of Jupyter and caused me to reinstall it but the problem persisted.
I have a Windows machine where I have installed anaconda (the latest version). There are two environments:
(base) Which contains nothing special maybe seaborn pandas etc. and is on python version 3.8.12.
(tf-gpu) Which contains tensorflow-gpu and is on python version 3.9.7.
Mind you, these two environments are created directly from a fresh installation of anaconda, and I didn't touch anything except installing tensorflow-gpu.
When I launch Jupyter through Anaconda, it launches normally on the home folder "C:\User\user" for both environments i.e. correct packages installed and correct version of python on both. I can also launch an instance of Powershell through Anaconda or Windows, (always in home dir), and launch Jupyter both environments behave as they should (packages, python version). So far so good...
The problem starts when I want to launch Jupyter from a directory other than home dir. I keep all my project files in a separate partition (D:), thus I navigate to that directory through a cmd/powershell (launched through Anaconda or Win) and type "jupyter notebook". The notebooks open on that director and:
When the base env is selected the notebook reports a correct name "base"(os.environ['CONDA_DEFAULT_ENV']) and python version 3.8.12 (sys.version_info). Everything behave as base env was setup.
When the tf-gpu env is selected the notebook reports a correct name "tf-gpu" but I get a python version 3.8.12, which is completely wrong! It should be 3.9.7. I can't import tensorflow since I get an error. Essentially I am in the base env without knowing it.
I then check in the same cli window (tf-gpu) that launched jupyter and python --version reports 3.9.7 and of course can import tf run it etc.
Jupyter just reports the environment name but in reality it uses the base environment even though it launched from said env. How can this change?
Why does Jupyter works normally when launched from the user directory?
If this is not solved easily, what is a workaround? Jupyter doesn't recognize symbolic links, and thus I can not navigate to another directory if it is not a subdirectory of home.
Finally, I also tried adding the env as kernel through python -m ipykernel install --user --name tf-gpu --display-name "Tensorflow GPU (tf-gpu)", but it doesn't seem to change a thing.
Update 1:
Of course I activate the tf-gpu through conda activate tf-gpu and check the python version and tensorflow (correct results), the problem is when launching jupyter notebook. The notebook reports the tf-gpu env but wrong python version and tf is missing.
Update 2:
After some searching around it seems that jupyter notebook has much trouble selecting a python version if multiple versions of python are installed in the system (in my case 2, 1 on each environment environments). Which is ridiculous if you think that that's why we are using environments for...
The reason you are having this problem I’m guessing is because your launched jupyter notebook from your conda base environment. You will see a (base) in your comment prompt.
To remedy this, When you use the command prompt to launch, do conda activate tf-gpu before you launch Jupyter notebook, now check if your versions are correct.
What I did and worked was run ipython3 notebook in the environment which launched the notebook server and everything was working properly correct environment name and correct python version and packages (tensorflow is working as it should). This must have updated some configuration files since I can now run jupyter notebook from a different folder and the gpu-tfu env works correctly.
Please remember that these problems were occurring only if I was launching jupyter outside the home directory (C:\User\user) on a different partition. Also keep in mind that this is a Windows installation and more complicated things may be happening with user paths, environments, etc than in linux.
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.
I have Python 3.6 installed on my windows computer. I just installed GraphLab Create and now when I open up my Jupyter Notebooks, it shows Python 2 instead of Python 3 which it always was before. How do I go about changing it back to Python 3 in the easiest possible way? Thank you
GraphLab Create only works in python-2.x. If you did use the GraphlabCreate.exe to install GraphLab, the .exe file installs Anaconda containing python 2.7 in your PC. So you have both python 2 and 3 versions in your system. You can find python3 jupyter notebook inside the Scripts folder in the location where you installed Anaconda3
Add the correct version of python(in this case python3) to your windows PATH variable
refer this link
Once you have the PATH variable setup you should be able to start python3 interpreter from the windows command prompt whenever you type python
Now when you type jupyter notebook from the terminal it should start the python3 kernel by default
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.
I'm completely new to Python and want to use it for data analysis. I just installed Python 2.7 on my mac running OSX 10.8. I need the NumPy, SciPy, matplotlib and csv packages. I read that I could simply install the Anaconda package and get all in one. So I went ahead and downloaded/installed Anaconda 1.7.
However, when I type in:
import numpy as np
I get an error telling me that there is no such module. I assume this has to do with the location of the installation, but I can't figure out how to:
A. Check that everything is actually installed properly
B. Check the location of the installation.
Any pointers would be greatly appreciated!
Thanks
You can determine which version of python you are running when you get the error by looking at the results of which python from the commandline. It is likely that you are running the system version (although recent versions Mac OS X include numpy in its system python), rather than Anaconda's python distribution. If this is the case, you need to modify your PATH as suggested by Anaconda at the end of the install process. Assuming it was installed in ~/anaconda, you would need to add something like:
export PATH=$HOME/anaconda/bin:$PATH
to your .bash_profile
Though the question is not relevant to Windows environment, FYI for windows. In order to use anaconda modules outside spyder or in cmd prompt, try to update the PYTHONPATH & PATH with C:\Users\username\Anaconda3\lib\site-packages.
Finally, restart the command prompt.
Additionally, sublime has a plugin 'anaconda' which can be used for sublime to work with anaconda modules.
I don't think the existing answer answers your specific question (about installing packages within Anaconda). When I install a new package via conda install <PACKAGE>, I then run conda list to ensure the package is now within my list of Anaconda packages.
you might want to try this:
for anaconda 2 :
export PATH=~/anaconda2/bin:$PATH
for anaconda 3 :
export PATH=~/anaconda3/bin:$PATH
for anaconda 4 :
Use the Anaconda Prompt
and then
conda --version
to confirm that it worked.