Revert Ubuntu 14.04 to default python after uninstalling anaconda - python

I am new to ubuntu and the whole linux environment. I installed Anaconda on my system, but I would like to use the default python now for some reason. I removed the anaconda directory , but now the system can't find the python installation (obviously, but I dont know how to get to the right one).
Can someone write out a step-by-step as to how I revert back to the original python (the default one ubuntu 14.04 comes with) ?
Thank you

In your .bashrc file you will have a line something like, Anaconda adds it during the installation process:
export PATH=$HOME/anaconda/bin:$PATH
You need to remove that line, do a source .bashrc and type python, that should open a shell using your system default python.

Related

How to deploy python programs in Anaconda environments on Windows?

I am trying to use Anaconda and conda environments to allow Python programs for data acquisition* etc. to run from the (Anaconda) command line on Windows. The set up will be that the Python programs are installed to a particular location (cloned from Github), within %PATH% or whichever environment variable is more appropriate.
From an Anaconda command prompt in another directory and a particular conda environment, I want (both myself and other users) to be able run either python test.py <args> or test.py <args> (either solution is acceptable) and have a system wide conda environment run its Python to execute the program. test.py can/will have an appropriate shebang set.
Right now the python test.py calls the correct Python within the active conda environment, but cannot find the test.py program as Python won't search the %PATH% or similar looking for the program. test.py does something (Windows does not complain that the executable can't be found, and I've been playing with the file associations to get this far), but doesn't appear to start Python - a simple print function or raise statement as the only entry in the file does nothing.
I've tried setting file associations in Windows, but this hasn't changed anything. I've copied the py.exe/pyw.exe across to the Anaconda environments, with no change.
Is this something that can be done within Anaconda, or am I going to have to fall back on installing base Python directly and trying to use the launcher mechanism there?
Note that I'm also intending to deploy these programs on Raspbian, so any solutions, including non-Anaconda ones, that will work cross platform there would be worth extra effort on my part.
*these programs have significant usage of library packages for accessing external USB/GPIB/serial/ethernet connected lab equipment and use matplotlib, scipy, etc., hence the desire for a cloneable conda environment as the base environment.
It turns out the correct answer to this is fairly simple, but is fairly hard to find explained well. This might be a little clearer than the other answers I found:
Install the standalone launcher from pylauncher and add #!/usr/bin/env python shebangs to your scripts.
This should register .py files to Python.File and will find your Anaconda Pythons in appropriate environments. If you don't have a non-Anaconda python, it will use the Anaconda base environment (these two facts were the key element I was missing from various other answers around this problem that I had looked at, including the documents on python.org).
If you have a Python from python.org installed, then a standalone command line shell will use that, defaulting to Python 2.x, then Python 3.x. With #!/usr/bin/env python shebang, then a regular command shell will try to use python.org pythons first, then the Anaconda base environment. An Anaconda prompt will use the active environment. #! /usr/bin/env python2 or python3 will try to use python.org pythons only and fail if they are not found.
Installing Python 2.7 from python.org installers (and letting the installer set the file associations) will break pylauncher, and reinstalling will not fix it. Instead, set Computer\HKEY_CLASSES_ROOT\Python.File\Shell\open\command default value to "C:\WINDOWS\py.exe" "%L" %* to revert back to the pylauncher set up (assuming you used the launchwin.* packages to install it).

change python directory from conda

Recently, I installed miniconda, and because of which, my default python directory seems to have changed to,
/home/user/miniconda3/bin/python
Also, the default version seems to have changed to python 3.7 instead of python 2.7
And I cannot seem to install various libraries like tensorflow.
How do I get my python back to normal?
The miniconda installation has properly added itself to your PATH. You can check whether /home/user/miniconda3/bin is listed when you run
echo $PATH
in a terminal. If so, it most likely added some lines to the bottom of your ~/.bashrc file. Simply remove these lines yourself, and your PATH should be back to normal (save the file and open up a new terminal), meaning that typing e.g. python will give you the system Python.

How to switch python version permanently, without "activating" environments?

I would like to be able to switch Python version permanently, in OS-wide manner and reboot tolerant, is it possible?
I don't want to use usual activate approach, which shows environment in command line prompt.
For windows, you can simply install a new version of anaconda and add it to the PATH before the old version (and any other python versions). Windows will then find this version of python first, and it will thus be your "OS-wise" python installation.
On windows, I think you just have to change your PATH environment variable and add the path to your favorite python.
I think you don't need to reboot your machine but you may have to restart your command line console (cmd.exe) to take it into account

Discover which version of Python is in PATH and how to change it

I am trying to use the the Rodeo IDE. However, according to the following error message, Rodeo can't find the right version of Python (I've installed the Anaconda distribution with Python 3.5, but according to the following message, that might not be the version of python Rodeo is trying to use):
"Bad news! Rodeo can't start. If you do have one of them installed, then the issue is that Rodeo is using the "wrong python". Rodeo defaults to using whatever python is on your PATH (or on Windows, whatever is set in your Environment Variables)."
Note, I use Mac OS 10.11.1.
I've tried to remove Python 2.7 (successfully, I think) and to reinstall Python 3.5 through Anaconda, but the trouble with Rodeo persists, I think because I have not changed the version of Python in my PATH.
How can I discover which version of Python is in my PATH and how could I change it to the version associated with the Anaconda distribution? Python beginner and answers can't be too simple.
In Terminal type
which python
to get the current python program path.
You can edit your ~/.bashrc and add the following with the path to your anacondas distribution at the end and then remove all other python paths in the .bashrc file.
export PATH=$PATH:/usr/local/lib/ <path to Anacondas...>
#for me it is /usr/local/anaconda/bin
Optional:
If you want to add other libraries / execute your own programs as if they were in the library or save yourself reinstalling everything, you can use the following:
export PYTHONPATH=/Library/Python/2.7/site-packages'
where you add the path of any libraries you wish to include.
If on Mac:
You have a .profile file instead of a bashrc. You therefore need to add the Path (above) to it and refresh your terminal. The easiest way is to use nano.
nano ~/.profile
#add:
export PATH=$PATH:/usr/local/anaconda/bin
# ctrl+x, then y, then rtn : to save and exit
#run bash or reopen terminal to refresh
bash
which python #should now be updated to anacondas path
I suggest try to use pyenv - https://github.com/yyuu/pyenv . It's simple to install and use and it has anaconda support. Also this plugin can be helpful - https://github.com/yyuu/pyenv-virtualenv .

How to integrate Django and Cygwin?

I have a Windows box with cygwin, python and django installed.
Now I want to run django-admin, but when I do I get the error:
$ django-admin.py
c:\Python26\python.exe: can't open file '/usr/bin/django-admin.py': [Errno 2] No such file or directory
From here
For Windows users, who do not have symlinking functionality available, you can copy django-admin.py to a location on your existing path or edit the PATH settings (under Settings - Control Panel - System - Advanced - Environment...) to point to its installed location.
hope this helps
I just ran into the exact same problem. I've found that if you already have the windows version of python installed, it seems to get priority over the cygwin version. I solved the problem by editing /etc/profile and changed:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:$PATH
...to:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:
...which I think stops cygwin from adding the normal windows path. Once you've got that working, download django into some directory, move into that directory and type:
python setup.py install
I was having problems to begin with because I had omitted the 'python' bit at the start
As for the step on how to start your django in cygwin
first open your windows command prompt
then register the python environment by doing this:
Path %path%;C:\Python27;C:\Python27\Scripts
then now go to the installation folder of your cygwin
cd C:\cygwin
then run the cygwin.bat like this:
C:\cygwin>cygwin.bat <enter>
then cygwin will open, and type python to see if it now working
$ python
Voila we are done!
Sort of sounds like the windows version of Python is trying to run instead of the cygwin one. What happens if you type this:
$ python django-admin.py
Here I'm assuming
$ which python
Finds the cygwin version of python (which will be something like /usr/bin/python).
You may also try (temporarily) uninstalling the windows version of python and use only cygwin.
Help us help you. Is there a reason why you are running the windows python interpreter (c:\Python26\python.exe) as oppose to the cygwin python interpreter (/usr/bin/python.exe)? That could be your problem. So to troubleshoot that, you might consider removing the windows native interpreter or simply making sure the cygwin path is listed before the c:\Python26 path in the windows global PATH variable.
Add the location of your django/bin folder (or wherever else you keep django-admin.py) to your PYTHONPATH environment variable.
Like Brian mentioned you are running the Windows version of Python which won't work with the Cygwin installation.
A word of warning. When I first started using Django, I tried installing it in Cygwin and had a variety of problems and ended up switching to the regular Windows version of Python. Unfortunately, I didn't document all my issues, but I remember some of them had to do with the database libraries. Anyway, that was a few months ago when I knew less about Django than I do now. Maybe the problems I ran into have been solved and perhaps now that I know more I could get it to work, but running Django on Cygwin does seem to be the road less traveled. Good luck. :)
Just copy the django-admin.py to the current location you are working on for e.g
on Cygwin:
<root>/projects/
on your windows directory it will look like this:
C:\cygwin\home\<your computer name>\projects\
once you copy the file, you can create your project by typing this command:
$ python django-admin.py startproject mysite
and that's all - you have completed your first project using the Cygwin linux-like environment.
Add two lines to .bash_profile and .bashrc files (view their difference here). You can find them in C:\cygwin\home\[username]:
export PATH=$PATH:/cygdrive/c/python2.7
export PYTHONPATH=$PYTHONPATH:/cygdrive/c/python2.7/Lib/site-packages
Hope this helps

Categories

Resources