In the Python installation on my PC there is a sweet script in C:\python26\tools\scripts called redemo.py. It's a simple tk application for testing regular expressions.
I wish I could get it--or something like it--running on my Mac, but I don't know how. The script doesn't appear to be part of the Python installation on my Mac. Ideas?
You can view the script directly from the python svn repository here and can download it:
curl http://svn.python.org/view/*checkout*/python/trunk/Tools/scripts/redemo.py?content-type=text%2Fplain > redemo.py
/usr/bin/python redemo.py
It seems to work just fine as is on OS X 10.6 with python 2.6.
Firstly, we should check whether the redemo.py is included in our system by using:
find / -name redemo.py # you can change the root searching path from `/` to other folder if you know the more specific path where python is installed.
Because some python distribution provider (e.g. Anaconda or default python in Linux/Unix distr.) sometimes will exclude this demo tool when install the python in our system.
If we found the redemo.py file within some python environments (assuming we have more than one python installed) then we can run it directly:
/right/path/python /right/path/redemo.py
But if there is no redemo.py file found in our system, we can still download this demo tool from official code repo (now at GitHub) and play with it.
curl https://raw.githubusercontent.com/python/cpython/3.6/Tools/demo/redemo.py > redemo.py
python redemo.py # Note the version is 3.6 in download path.
Mac OS X comes with Python pre-installed. As of 10.6.2 it has Python 2.6.1 found at /usr/bin/python. Copy redemo.py to your Mac. Make sure you have X11.app running and open a terminal (Terminal.app is available by default) and just run:
% python /path/to/redemo.py
Assuming there aren't any Win32 specific hooks in this script, it should execute.
Install Python on your Mac, then copy the script over? It should work fine on any Python installation.
Python is part of OS X, but sometimes it's a bit out of date: http://www.python.org/download/mac/
Related
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.
I want to make a portable app that would have some code and python executable that would run on any Windows even if python is not installed.
I would like it to be python 3.6 and so it has only pip and setup tools installed.
EDIT: concerning duplicate
not quite. I don't want to compile the code. I wanted to give them .py files but realize that Windows won't have python installed on default. I want something that can be carry on a flash drive but will run my code from source not binary.
Please correct me, if I understood it wrong. I think there are at least two ways to do it.
suppose you have one portable_run.py script you want to run everywhere on a flashdisk.
Make a exe file with pyinstaller for example. you can get a exe file like portable_run.exe. On target windows system what you need to do is to run the exe direcltly protable_run.exe
Use a portable python distribution like winpython or python-xy. you just need to copy this portable distribution on the flash disk together with your portable_run.py. To run it on target system flashdisk/path-of-winpython/python portable_run.py
Hopefully it could give you some idea.
I also encountered the same problem and managed to create a portable python with Python's official Windows embeddable package.
I wrote the steps into a ps1 script so I can easily repeat the process without going through the pain.
The steps:
Download the portablepy.ps1 from the repo :
https://github.com/Dreamsavior/portable-python-maker
Create a blank folder, put the portablepy.ps1 to that folder.
Execute the portablepy.ps1
The script will create a portable python 3.9.10 with pip in the current folder by default.
To install custom version of Python run the script with -source and -destination parameter
.\portablepy.ps1 -source "https://www.python.org/ftp/python/3.9.10/python-3.9.10-embed-amd64.zip" -destination "C:\SomeDir\PortablePython\"
Where the -source is the url of the Python's Windows embeddable package from this page: https://www.python.org/downloads/windows/
And -destination is the path of your folder (ended with backslash).
I bought my mac about a year ago and somehow changed my python symlink so that when I run python some_file.py, python 3.4 is used to run the file instead of python 2.7. I now need to change it back, but I can't figure out what I did to change it in the first place! When I run:
import os
os.path.realpath("/usr/local/bin/python")
in the python terminal, the output is:
'/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7'
Does this not mean that my python symlink is pointing to my python 2.7 version, and not my 3.4 version? If not, how do I find out which file is run when I use the python symlink?
You probably installed that specific Python version using the official Python installer for OS X; see the Using Python on a Macintosh documentation. The installer creates the /usr/local/bin symlink for you.
If you also, at some point, had 3.4 installed then that installation is still there too. Check for a /usr/local/bin/python3 command; it'll link to the existing Python 3 binary. Use that instead to run Python 3 code.
If you do have a /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 command, you could re-create the /usr/local/bin/python symlink to point there instead, but I'd personally only use the python3 name for Python 3 scripts.
Last, you could also have used the homebrew tool to install Python; it can manage symlinks for you. However, homebrew installs Python binaries into the /usr/local/Cellar tree structure instead.
I know how to start PyCharm in 32-bit mode on OSX Lion, but how do I get the interpreter configured in PyCharm to use the 32-bit version of the Apple shipped Python version (currently 2.7.1)?
I successfully have it working when launched from the terminal, but it appears that PyCharm doesn't read those system variables or defaults.
I'm trying to get cx_Oracle working with some scripts in PyCharm. Please see the following question for more details:
Can't get cx_Oracle to work with Python version 2.7 / mac os 10.7.2 (Lion) - missing_OCIAttrGet
Thanks in advance for your response!
I don't use PyCharm so I can't test this but it appears you can configure a non-standard path to the Python interpreter (see PYCharm help here). If so, try using /usr/bin/python as the path. If you've used the defaults command to permanently set 32-mode (as documented in Apple's man python):
defaults write com.apple.versioner.python Prefer-32-Bit -bool yes
that should do the trick. Setting the environment variable probably won't work.
UPDATE: Since you report that that does not work, here's another, more drastic possibility. You can extract the 32-bit architecture binary from the multi-architecture (universal) binary by using the lipo command. Try something like this:
sudo lipo /usr/bin/python2.7 -extract_family i386 -output /usr/local/bin/python2.7-32
sudo chmod 755 /usr/local/bin/python2.7-32
Then set the interpreter path in PyCharm to that file. It's ugly because you will need to keep an eye on any Python updates from Apple and repeat the process. If PyCharm is exec-ing the Python executable directly from the framework, then this may not work. Short of getting some support in PyCharm or resolving the Oracle issue, the fool-proof solution would be to install a 32-bit-only version of Python. The pre-built 32-bit-only installers from python.org are problematic for Lion 10.7 because of their dependence on gcc-4.0 and the 10.4u SDK, both no longer provided in Xcode 4. However, you could build it yourself or, with a little bit of configuring, you should be able to get MacPorts to build one.
For some reason none of that worked for me. Kind of lame that pycharm doesn't support this..
I ended up adding the BASH support plugin to PyCharm: Preferences > Plugins > Browse Repository > BashSupport
Then I add a new bash file to my project with the content:
#!/bin/bash
arch -i386 /usr/bin/python ./<your script name that's in the same directory here>
Run it by right clicking and running. Now it'll appear in your 'configurations' drop down.
Now you can run the script as 32-bit python, see the standard out, and edit the .py file.
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.