not able to uninstall python and get python 3 - python

i just started using python and i use VS Code.
When i do
python --verion
i get python version 2
py --version
i get python version 3
i wanted to install networkx which turned out to only work with python version 3. I did multiple things to change python version to 3 but could not.
So i decided to uninstall python and went to control panel and uninstalled
python
python launcher
and restarted the computer.
But when i run
python --version
it still shows up python 2.7.18
and this is my where python output
can anyone please help me to understand whats going on and how can i get python 3 to my system.
My solution:
I had already tried putting the python 3.1 path (default added by python when you click add path option while installing) above all path but had no intended outcome.
What i did:
installed python again and this time added the path by myself and moved it to top.
Now when i run
where.exe python it shows me three path, i don't know much but looks like there are two/three python in the system but it started showing python 3 for now.
my where.exe python output:
uninstalled

In windows If you do not have correct environment variable set then this is likely to cause the problem.
On your Powershell if you type $env:path or on command prompt echo %PATH%
you shall see your environment variable path which you have set,
where-in, either you may not have path to directory of Python 3 or you have it appended after Python2.
i.e.:
if your result show up as (... could be other paths in your variable) then only you will get python.exe to be pointing to your Python3 path:
...
C:\Python38\Scripts;C:\Python38;
...
C:\Python27\Scripts;C:\Python27\;
...
Update:
Based on OP comment it looks like there is misunderstanding with how environment variable works.
If you are still looking for why question then follow below steps:
List down all paths which are under environment variable PATH
Now go over each path and check contents of the directory. One of the directory would be having the python which is throwing you the version which you find mystery.

Related

Python conflicts when importing?

I have windows 10 with 2 user accounts, one is an old one that has Python installed. My latest account also has Python installed. I used pip install tweepy, and it now exists in the site packages. If I open my Python shell (v3.6.5), it imports fine. However, I can't get this to work when switching to Python in cmd. In here, after typing python, it says Python 3.6.6. Obviously they are different, yet they seem to be originating from the same directory.
Any ideas?
[edit] I have just realised that I have an external application that runs on Python 3.6.6., so I guess it's defaulting because of that. However, I can't uninstall that since I need it - is there a way to specify which version of Python is launched when I type python into the cmd?
[edit2]: This is the issue, and the solution there works. However, I want to be able to just type python into cmd, rather than the entire path. Since both exist in the path (and I don't want to remove the other 3.6.6.), is there a way to achieve this?
Have you thought about using a virtual environment?
https://virtualenv.pypa.io/en/latest/
When you enter "python" into your cmd it searched python.exe in the directories listed on your PATH variable.
All you need to do is to modify your PATH and add the directory path in which the python with the desired version is located.

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.

VS Code not detecting Python3 interpreter on MacOS

I just upgrade python3 to 3.6 (using homebrew) and now VS Code doesn't seem to be aware of it. When I try to select my Python interpreter I see 2.7.9 and 2.7.10 (in /usr/bin and /usr/local/bin respectively) but I do not see 3.6.3 (/usr/local/bin/python3).
It's certainly in my path, and I'm aware that I can update settings.json manually, but I use both Python 2 and 3 for various projects and making them available via the interpreter switcher would be incredibly useful. Any ideas why Code isn't autodetecting python3? Or is there a way for me to force-add it to the list?
Figured it out. Something I clearly installed had modified by .bash_profile to include the following:
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
I commented that out, restarted Code, and now I can see all my Python interpreters listed (including 3.6.3).
In VS Code, you're able to easily set the interpreter you'd like to use for Python. Follow this official guide.
From the site:
To select a specific interpreter, select the Python: Select Interpreter command from the Command Palette (⇧⌘P).

Incorrect module path in Python

I recently had a problem with importing a python and therefore posted this question: Cant seem to import specific module in Python
Based on input I got I did some digging and saw the following:
If I open cygwin and input python --version, I get this
Marc#Marc ~
$ python --version
Python 2.7.12 :: Anaconda 4.2.0 (64-bit)
And if I open python using myCharm and input this:
import sys
print('\n'.join(sys.path))
I get:
C:\Users\Marc\Anaconda3\python.exe C:/Users/Marc/PycharmProjects/clustering/testing.py
C:\Users\Marc\PycharmProjects\clustering
C:\Users\Marc\PycharmProjects\clustering
C:\Users\Marc\Anaconda3\python35.zip
C:\Users\Marc\Anaconda3\DLLs
C:\Users\Marc\Anaconda3\lib
C:\Users\Marc\Anaconda3
C:\Users\Marc\Anaconda3\lib\site-packages
C:\Users\Marc\Anaconda3\lib\site-packages\Sphinx-1.4.6-py3.5.egg
C:\Users\Marc\Anaconda3\lib\site-packages\win32
C:\Users\Marc\Anaconda3\lib\site-packages\win32\lib
C:\Users\Marc\Anaconda3\lib\site-packages\Pythonwin
C:\Users\Marc\Anaconda3\lib\site-packages\setuptools-27.2.0-py3.5.egg
So assume this highlights the problem. Could anybody tell me what is wise to do here? Change the path in my terminal of change the path in python
If you set an envirnment variable called PYTHONPATH to a colon-separated (Windows: semicolon-separated) list of directories, each of them will be added to the interpreter's sys.path. This is the recommended way of making modules available.
So for example, let's suppose you had added Python modules in the directory C:\Documents and Settings\frits\private. Before you run your Python program you would execute the command
SET PYTHONPATH=C:\Documents and Settings\frits\private
No semicolon is required in this case because there's only one directory.
The when you run Python you will find that your sys.path has another entry corresponding to the C:\Documents and Settings\frits\private directory.
In the longer term, to avoid conflicts between the requirements of different projects (e.g. you want to run two programs that require a different version of the same third-party module) you should investigate the use of virtual environments.

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 .

Categories

Resources