Setting Python Interpreter in Eclipse (Mac) - python

How do I direct Eclipse to the Python interpreter on my Mac?
I've looked in Library which contains the directory 'Python' then '2.3' and '2.5', however they contain nothing except 'Site-packages' - Which is weird considering I can go into the terminal and type python. I then installed the latest 2.6 version with package manager and still can't find it. Can anyone help?

An alias to the python interpreter was likely installed into /usr/local/bin. So, to invoke python2.6, type /usr/local/bin/python2.6 or, most likely, just python2.6. If you want python to invoke python2.6, try rearranging your $PATH so that /usr/local/bin precedes /usr/bin.

Running $which python should help locate your Python installation.

I just solved this for my Mac and it was located in
/usr/bin/python2.7
The way I found it is as follows:
(1) I tried entering the following to see if I could find where Python was located
echo $PYTHONPATH
This had the location of a custom install of Python that came from another program I downloaded, but I wanted the native Python.
(2) I wanted to see every folder in the path so I could look for python
echo $PATH
This returned the following:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/sbin
(2b) I CDed into every one of these locations and searched for python in each one.
cd /usr/bin/
ls | grep "python"
And I eventually found Python.
In Eclipse, with PyDev, if you (1) click Preferences (2) PyDev (3) Interpreter - Python, you can add the interpreter.

If you have installed python on mac, follow belows steps (on eclipse neon)
Click on Preferences
Search for python
Below screen will appear
Click Choose from list
It will show up all the python installed and select one for you
Hope it helps some one. It resolve my problem.

Related

Cannot find Python 3.8.2 path on Windows 10

I have Windows 10 on my computer and when I use the cmd and check python --version, I get python 3.8.2. But when I try to find the path for it, I am unable to find it through searching on my PC in hidden files as well as through start menu. I don't seem to have a python 3.8 folder on my machine. Anybody have any ideas how to find it?
If you can open the python interpreter sys.executable will give you the path.
import sys
print(sys.executable)
Python paths in Windows can get a little strange. I prefer to use the official packages from python.org. And I use the "install for all users" option. Finally, I prefer to have my Python installs one level below C: drive, i.e. C:\Python37.
If you do not use the "install for all users" option, the Python directory gets buried in C:\Users\xxx\xxx somewhere. And some IDEs (I'm looking at you PyCharm) like to install everything in virtual environments (venv).
#moeen.n answer of sys.executable is probably the easiest to find out where your install is.
If you're using cmd (ie Command Prompt), and typing python works, then you can get the path for it by doing where python. It will list all the pythons it finds, but the first one is what it'll be using.

Why is python setup popping up when I start Pycharm and where is my python interpreter?

When I start Pycharm, this python setup menu pops up.
Python 3.7.4 is not even the version I'm using. Everything else works fine and I can just close it, but it is annoying.
There was a same question, and the answer was
You appear to be using the installer .exe as if it were the Python interpreter. Install Python to somewhere first, then use the python.exe in the bin directory inside that.
But I can't find where my bin directory is. My Python37-32 folder looks this.
How do I find my python interpreter?
Open some project -> File -> Settings -> Project: ... -> Project Interpreter -> Show All ... to view the list of available interpreters added to PyCharm.
Find and remove the interpreter which is pointing to Python distributive from the newly opened list.
At some point in past you added Python installer as a project interpreter in PyCharm so now when IDE tries to use this exe to run some background tasks (e.g. to get sys.path) installation wizard is triggered instead.
Correct python.exe to point PyCharm to is right on your screenshot
According to official python documentation.
The Python interpreter is usually installed as
/usr/local/bin/python3.8 on those machines where it is available;
putting /usr/local/bin in your Unix shell’s search path makes it
possible to start it by typing the command:
Since you are using Windows here, you are already in the location where the python interpreter resides. So look no further.
By the looks of the screenshots, I have a concern whether you have installed python correctly.
If you did not select the checkbox for Add Python 3.7 to PATH, the wizard expects you to do it manually which is why the error.
I would uninstall and reinstall Python and this time make sure to check that box. I am sure your error messages should go away.
Alternatively, if you're not in the disposition to uninstall. According to python docs here you can set the python variable to PATH variable and try.

python27 and python3 are not not recognized as an internal or external command, operable program or batch file [duplicate]

I am using Python 3.5.2 version on Windows 7 and tried using python3 app.py. I am getting this error message:
'python3' is not recognized as an internal or external command,
operable program or batch file.
Is there any specific cause about why the python3 command is not working?
I also verified that the PATH is added to environment variables.
There is no python3.exe file, that is why it fails.
Try:
py
instead.
py is just a launcher for python.exe. If you have more than one python versions installed on your machine (2.x, 3.x) you can specify what version of python to launch by
py -2 or
py -3
You can also try this:
Go to the path where Python is installed in your system. For me it was something like C:\Users\\Local Settings\Application Data\Programs\Python\Python37
In this folder, you'll find a python executable. Just create a duplicate and rename it to python3. Works every time.
Python3.exe is not defined in windows
Specify the path for required version of python when you need to used it by creating virtual environment for your project
Python 3
virtualenv --python=C:\PATH_TO_PYTHON\python.exe environment
Python2
virtualenv --python=C:\PATH_TO_PYTHON\python.exe environment
then activate the environment using
.\environment\Scripts\activate.ps1
Yes, I think for Windows users you need to change all the python3 calls to python to solve your original error. This change will run the Python version set in your current environment. If you need to keep this call as it is (aka python3) because you are working in cross-platform or for any other reason, then a work around is to create a soft link. To create it, go to the folder that contains the Python executable and create the link. For example, this worked in my case in Windows 10 using mklink:
cd C:\Python3
mklink python3.exe python.exe
Use a (soft) symbolic link in Linux:
cd /usr/bin/python3
ln -s python.exe python3.exe
In my case I have a git hook on commit, specified by admin. So it was not very convenient for me to change the script (with python3 calls).
And the simplest workaround was just to copy python.exe to python3.exe.
Now I could launch both python and python3.
If python2 is not installed on your computer, you can try with just python instead of python3
For Python 27
virtualenv -p C:\Python27\python.exe django_concurrent_env
For Pyton36
virtualenv -p C:\Python36\python.exe django_concurrent_env
Enter the command to start up the server in that directory:
py -3.7 -m http.server
I had a related issue after installing windows 11, where python3 in cmd would open the windows store. I was able to sort it out between this post and this other one. In short, I reinstalled python and made sure to add it to PATH. Then, in settings, Apps > Apps & Features > App Execution aliases. Here, all I had to do was make sure that every single python .exe (including idle and pip) were turned off EXCEPT FOR the python3.exe alias. Now it works like a charm.
FWIW:
The root of this issue is not with you or with python. Apparently, Microsoft wanted to make installing python easier for young kiddos getting interested in coding, so they automatically add an executable to PATH. For those of us that already have this executable, it can cause these issues.
Found out instead press the play button the top right and it should work in visual studios:
Do not disable according to first answer
Saying python3 in the command will not work by default.
After figuring out the problem with the modules (Solution): https://youtu.be/paRXeLurjE4
Summary:
To import python modules in case of problem to import modules:
Hover over python in search:
Click open in folder
Hover over and right click
click properties
copy everything in path before \python.exe
close those windows
For cmd (administrator):
cd --path that was copied--
then python -m pip install --upgrade pip
cd Scripts
pip install "Name of Package" such as pip install --module (package) --
Im on win10 and have 3.7, 3.8 and 3.10 installed.
For me "python" launches version 3.10 and does not accept commands (like -3.7), "py" launches newest version but does accept commands, and "python3" does nothing.
Uninstalled 3.10 and "python" now does nothing, and "py" launches 3.8.
I am unable to add a comment, but the mlink option presented in this answer above https://stackoverflow.com/a/55229666/8441472 by #Stanislav preserves cross-platform shebangs at the top of scripts (#!/usr/bin/env python3) and launches the right python.
(Even if you install python from python.org, Windows will direct you to the app marketplace nowadays if you type python3 on the command line. If you type python on the same cli it will launch the python.org version repl. It leads to scripts that generate no output, but more likely silently failed completely. I don't know ho common this is but have experienced it on a couple of different devices)
If you have this at the top of your script to ensure you launch python3 and don't feel like editing everything you own, it is not a bad approach at all... lol.

Pycharm, can not find Python version 2.7.11

I installed Python 2.7.11 on this Mac, and from terminal Python 2.7.11 can be started. However,
From the interpreter of Pycharm (2016.1 version) , there is no Python 2.7.11.
Any suggestions ? Thanks
PS:I successfully did this on one Mac, but for some reason I cannot make it on another Mac... odd..
if you cannot find from the list, you can add it manually,
https://www.jetbrains.com/help/pycharm/2016.1/configuring-local-python-interpreters.html?origin=old_help
you need to specify the python path in the add local dialogue. you mentioned that you can start python 2.7.11 from your terminal, then type 'which python' in your terminal and get your python path. copy paste this path to your PyCharm "add Local" . e.g:
bash-3.2$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Just click on the python in the first image you uploaded. It will work.

PyDev Eclipse Python interpreters Error: stdlib not found

I have been trying to use Eclipse 3.6 as a Python editor.
I install the latest version of PyDev, and then try to set the Interpreter - Python field of the preferences, on my mac.
My python version is 2.6 and the path is "/usr/bin/python". When I enter this, and I select the items to add to the system PYTHONPATH I get the following error message:
Error: Python stdlib not found
It seems that the Python /Lib folder (which contains the standard
library) was not found /selected during the instal process.
This folder (which contains files such as threading.py and
traceback.py) is required for PyDev to function properly (and it must
contain the actual source files, not only .pyc files) ...
So I can't tell eclipse the interpreter path!
Any help would be great!
(I tried reinstalling PyDev already, no luck)
Thanks!
Following Praveen's answer, My python library is in /library/python/2.6/site-packages. When I enter /usr/bin/python into the interpreter field, eclipse asks me which paths I would like to add to my System PYTHONPATH. One of the checkbox items is exactly that path. So I check it, along with the other boxes. Click ok, and I get the same error.
Had the same problem. Eclipse wouldn't find all the required path using the default installed python (2.6). I downloaded python 2.7, went through the install. My new "which python" path became:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python.
When I tried to set up the interpreter this time, specified this path and it went right through.
Note:
Browse to /Library/Frameworks/Python.framework/Versions/2.7/bin directory
Select the python interpreter that's installed. Sometimes the 'python' link doesn't exist to the current interpreter (say, python3)
just found an answer to my own question, thought it might enlighten other users with similar problems. I will try it out later to see if it works.
On SourceForge: http://sourceforge.net/projects/pydev/forums/forum/293649/topic/4480085:
tim-erwin writes:
"I downloaded the Python source release and simply dropped the /Lib folder into the /System/..../Frameworks/.../lib/python2.6/ and it works."
fabioz writes:
"That's a solution (although usually what I do on Mac OS is getting a python install from python.org instead of using the default one -- not sure what you may break in Mac OS if something bad happens there while developing)."
When I upgraded to Mountain Lion (10.8.2) I had this problem. The solution was to install XCode 4.5.2, then in XCode > Preferences > Components, there is an option to install the Command Line Tools. I installed them and then I was able install Interpreter.
PyDev needs the location of the python lib folder to get this directory location on your computer try running this command in the terminal.
python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
And add that directory to your PYTHONPATH location in PyDev in Eclipse.
For OS X 10.8 (Mountain Lion) I found a solution here: pydev debugger: unable to find real location for python 2.7 after OS 10.8 upgrade
Seems that there are no command line tools installed by default, so you have to go download them...
I too had the error: stdlib sources not found.
My fix was to install XCode 4.2 and then retry Eclipse's PyDev "Auto Config" method.
No error. PyDev running OK!
I found the solution of not touching macs deliverd python version, but downloading ad installing a new one (currently 3.something)
when setting up the interpreter, point to /usr/local/bin/pyhton3
(to find out the exact path open terminal and type: sudo -s !hittenter> your password !hittenter> cd /usr/local/bin !hittenter> ls !hittenter>)
-> what this does is, showing you the content of the folder you went to. you should find the python interpreter in there.
WARNING!!!!
Do not touch or change any other python files/folders delivered with your mac.
After installing Apple's OSX Developer tools from http://developer.apple.com/xcode/, the necessary .py files will be installed in /library/python/2.6/site-packages. No need to fuss with installing python yourself of using versions of Python not blessed by Apple.
#labjunky , if the .py files from the lib folder in the source tar ball are dropped into the User's site-packages folder ~/Library/Python/2.7/lib/python/site-packages[ provided it is listed in the locations by PyDev and selected] , it works too. this can be useful if the user does not have permission to modify the location in /System/Library/Frameworks/....
In Preferences > PyDev > Interpreter - Python
Choose New...
Name it "Python2.7"
set the path to /usr/bin/python
it then auto-configs some paths, select them, and it proceeds.
I had this issue setting up Jython and solved it as described here: https://stackoverflow.com/a/20002281/1915920
I decided to leave my MAC OS Python 2.7 as is, and instead just install Python 3.3.4.
It works smoothly! :)
1) download python 3.3.4:
The python-3.3.4-macosx10.6.dmg is from http://python.org/download/releases/3.3.4/:
downloaded "from Mac OS X 64-bit/32-bit Installer (3.3.4) for Mac OS X 10.6 and later" (My Mac OS is Mountain Lion).
2) setup Python Interpreter and Lib:
Go to Eclipse Preferences > Interpreter > Python Interpreter and click "Quick Auto Config". It is able to locate the Python 3.3.4, find the interpreter as /usr/local/bin/python3 (which is actually: shulow$ ls -l /usr/local/bin/python3
lrwxr-xr-x 1 root wheel 69 4 Mar 23:18 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/python3)
And it also automatically find the respective libraries in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3 which has the .py files (rather than only the .pyc and .pyo)
I got this error because I downloaded the embedded zip file version of Python and extracted it to a folder. I then downloaded the actual installer and ran it. That gave me the stuff that I was missing.

Categories