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.
Related
I tried the command in my cmd and this is what is said, I don't really know what it means though, and I still can't use NumPy in IntelliJ.[This is the whole thing, it says NumPy isn't there even though I find it in the external libraries when I go through them.]
Make sure that your IDE (wherever you're running your Python program) runs in the same environment that the one where you install your packages. It appears like you have 2 environments: One with "native Python" installed in your machine (where your program runs), and an Anaconda environment (where you installed numpy).
I recommend you stick with Anaconda and use it only. In your Start Menu, search for "Anaconda Prompt". There you can install any packages you want, but it seems numpy is already installed. Then you can type, for example, code to open VS Code, or jupyter notebook to run Jupyter. Or type python and start coding.
But if you really want to use a program outside Anaconda environment, then you have to install your packages in your "native Python" environment. You can do such using the Windows cmd or PowerShell, instead of Anaconda Prompt.
I need to downgrade from python 3.8 to python 3.6 for Tensorflow in a virtual environment
I usually create environment with python -m tempenv /path/to/venv
I noted from this article that you can specify the interpreter when creating a virtual environment
https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/
But this requires downloading the interpreter separately
Is there a way to automatically do this in an elegant command or set of commands? So that it would download the needed version of Python (3.6) and the appropriate pip installation in the virtual environment folder?
You can only create a virtual environment for the version of Python you're using to create it with.
Having said that, if you need virtual environments for different version of Python (e.g. 3.8.x and 2.7.x), you can simply install both version of Python and use the appropriate one to create new virtual environments with that version of Python in it.
As suggested by #flakes, you can also package managers to further automate the process and avoid having to manually pick and install versions of Python to use - to your preference. Tools like pyenv can then make your life easier switching between versions of Python. However, then we're getting into opinions on what's better or easier - you can make it work with stock Python as suggested.
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 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.
In my Ubuntu16.04, there are python 2 and python 3 default. In addition, i have installed anaconda too. I am sucked by the 'python' cmd. Every time i use pip or pip3 install, I don't know where the package install, python2 or python 3? And I use conda install to install anaconda package. I also use anaconda env to manage different virtual env. But I think it mix with my local Python 2 and 3.
For example, in directory /usr/bin, I found many soft links like this:
When i try 'python' cmd, it just confuse me!
Why python3m are local, shouldn't it be anaconda? Why python3 are anaconda, shouldn't it be local? Then I found that if I use ./python2 or ./python3, I found it is correct now!
So I know it is caused by environment variables. I echo $PATH, Found it like this: /home/kinny/.pyenv/shims:/home/kinny/.pyenv/bin:/home/kinny/anaconda3/bin:/home/kinny/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/ant/bin:/snap/bin:/opt/maven/bin:/usr/lib/jvm/java-8-oracle/bin
I have used update-alternative --config python to configure default python, but it doesn't work! It sames mixed with each others.
Now I just want to install tensorflow 0.11 in local python3, because in anaconda it is 0.10 version by default. So how can I change this. I just want to use python python3 and python3m represents python2.7 python3.5 and anaconda python respectively, How can I do that! use pip and pip3 for local python2 and python3 respectively!
I ran into a similiar problem when setting up PyCharm Edu to work with Anaconda. I found that I had several versions of Python installed and it was very hard to keep track of which version the IDE was referencing. My CS professor gave me the advice of simply removing the versions of Python I didn't frequent. I now just have Anaconda installed; and use the Anaconda Prompt as my Python console. I also rely on PyCharm's IPython for the developer console. However, if you still want differing versions of Python installed (say your doing QA testing for older devices); there is the really helpful command: which python. When entered into the python console or Anaconda Prompt: which python will display the directory associated with the currently executing Python Shell. This enables you to better keep track of to what particular python.exe the current window is referring to.
Follow up to the comments mentioning using virtualenv and virtualenvwrapper.
Here are the official docs and a good blog post to follow for getting started using virtualenv's is here:
https://virtualenv.pypa.io/en/stable/installation/
http://virtualenvwrapper.readthedocs.io/en/latest/install.html
http://exponential.io/blog/2015/02/10/install-virtualenv-and-virtualenvwrapper-on-ubuntu/
Also, once you are setup you can create virtualenv's specifying which python installation you want to use.
which python3
returns
/usr/bin/python3
Then create a virtualenv with that python path. Where example_env is the name of the virtualenv.
mkvirtualenv -p /usr/bin/python3 example_env
Then activate the virtualenv using virtualenvwrapper.
workon example_env
Finally, install tensorflow and other dependencies with pip.
pip install tensorflow
the which command is very useful for finding the path to the executable that is first in your path. Zsh also has the where command, which will show you all instances of the given executable that show up in your path. For managing different python versions, you have a lot of options. The easiest for most people tends to be anaconda, using conda environments. The installer will ask you to add some stuff to your .bashrc file, which will then make anaconda's binaries come first in your path. Anything else you run after the .bashrc gets sourced after that, will then use that first, including PyCharm. For graphical desktop apps to pick up the change, you may need to log out and back in again. If you only need one version each of python 2 and python 3, you can just use the ones available via apt. Depending on your Ubuntu version, Python 2 is definitely installed by default as it is used by many system utilities, including apt itself. Some newer versions may also install python 3 by default, but I do not remember for sure. Another option is to install the versions of python you need in an alternate location, such as /opt/python/<version> and then using environment-modules (installed via apt install environment-modules) or Lmod to control which versions are being used, but that may or may not be easy/convenient to use with a desktop application such as PyCharm.
for TensorFlow, 1.11 is available in anaconda, but I don't remember if it's in the default channel or not.