.py files default to Xcode on Mac? - python

When I open a .py file on my Mac it opens in Xcode but wont run.
Why does this happen and how do I fix this?
Xcode doesn't seem to recognize Python syntax. How do I fix this? (for example True and False are not recognized as keywords)

The default application for .py files on Mac is set to open in Xcode. Usually at installation time, you're provided with a list of checkboxes of extensions to associate with the program you're installing.
To fix this, follow this tutorial:
http://www.imore.com/how-change-default-apps-os-x
Also, it doesn't recognize regular Python syntax because it's not configured to run Python. By default it's set to Objective C/Swift. You need to associate a project with a Python interpreter for it to pick up the syntax.
To setup a Python project in Xcode, follow this tutorial:
https://stackoverflow.com/a/5438416/4889267

Related

Unable to change Python 2.7 to Python 3.8 on Sublime and VS code

I have been trying to change my python interpreter on sublime text and VS code and no matter what I do, both of them refuse to change. It always picks the default Python 2.7 version.
On sublime, I tried to create a new build tool, added the path to Python3 but nothing is working.
And on, VS code, even if I select Python3 from the drop-down menu, it doesn't change anything.
I changed the system's default python interpreter from 2.7 to 3.9 and set the path on bash profile. It fixed the issue for me.
I don't know about Sublime, but for VS Code, there looks to be quite a few things to verify:
Check your User Settings on whether you've set up a default interpreter for your applications
Are you using Window 10 WSL? Then you might want to check out issue 3227 for vscode-remote-release where the comment was:
So I was having this same exact issue until I read this article on a wsl tutorial. In there it says we should have "Remote - WSL" extension installed (already did). In the bottom left corner "Remote - WSL" installs a status button that has the "greater than" and "less than" symbols displayed. If you click that button and tell VSCode to open up in the remote WSL distro environment it fixed my issue where vscode was unable to find an interpreter for python.
For Sublime, you need to hit ⌘B with your script pane focused in order to use your new python3.sublime-build build system.
It looks like you are running your script within Terminus, which is fine, but you need to use the python3 command when running it from the command line, even if that command line is within Sublime.
Please check out my answer here on how to make a Python build system that accepts user input, as the Sublime "console" doesn't allow you to interact with your program. Since you already have Terminus installed, I'd recommend going down to the bottom of the answer and using the Terminus build system. That way, you won't have to deal with Terminal windows opening every time you run a build.
The terminal window uses your PATH, not the IDE settings, so manually typing out python --version isn't testing anything except the PATH variable
In order for the terminal to use the "correct" python binary you've specified, it would need to give the absolute path to it, which I believe using Command+B (using the build options) in Sublime would do. Similarly, you can use the Run/Debug Configurations in VSCode.
Or you can modify your ~/.zshrc to fix your PATH, for example installing pyenv to change the entire system Python version, or the one for the current folder

How to force a Python .pyw executable to open in a specific Python version?

I have a program that I wrote a while back and converted into a .pyw executable file. It worked fine but recently I installed a different version of Python so I could use an outdated library, and now my .pyw won't open.
I'm assuming this is because it doesn't know which version of Python to use. The only way I can get it to open is to right-click the file, and choose to edit in IDLE 3.8 32bit, then run from there. Its very long winded compared to just running the file from my desktop. Of course I can also use the command line but its also longwinded.
Is it possible to add a line of code to the file which will force it to open in a specific Python version? I need to be able to specify the version and also x86/64, since I have Python 3.7, 3.8(64) and 3.8(32).
Note: please don't get onto me about having multiple versions installed I'm well aware that its not ideal but it was necessary for a project I'm doing :)
If you had installed Python with the py launcher on Windows, you can set a shebang line with Python 3.8.
For your case, you might want # python3.8-32 or # python3.8-64 or # python3.7.

Basepath argument is not fully qualified. Parameter name: basePath. I can not use code completion

I just open a .py file on visual-studio-code. And I got a message:Basepath argument is not fully qualified.
Parameter name: basePath. And I can not use python completion. The source of this message is Python(Extension) of Microsoft.
Here is image description
I had the same issue today, and I opened a folder in VSCode(The path of you .py file. You can see the option in your image). It seems that it works for me now. I'm not sure whether it will be helpful to you.
Same thing happened to me, it started today.
I checked my Python install, python path in sys, reinstalled VSCode and no changes.
Im using Python 3.7, win 10.
In the end what solved it for me was in settings.json, in VSCode, set "python.jediEnabled": true and after that VSCode prompted me with a warning that one of the extensions uses the language server (sorry i forgot the name of the extension, it was an old python autocomplete extension), after removing that extension everything was working fine.
As far as i understand it was a problem with the ms language server, jediEnabled setting configures the VSCode to use Jedi as the IntelliSense engine instead of Microsoft Python Language Server, some extensions require ms lang server so if you remove them you should be good.
Give it a try, hope it helps.
I had the same issue yesterday and solved it this afternoon.
The source of this message is also Python(Extension) of Microsoft.
But, and i assume this is maybe the same for you, it was linked to "IntelliCode extension for VS Code (preview)" which asked me to activate pylit.
So the only way i found to repair the software was to delete my preferences files to reset Visual Studio Code and boot like the first time.
Then i re-installed my extensions and preferences.
You do not need to uninstall the soft.
Note that uninstalling Visual Studio Code won't change anything if you don't delete manually the preferences files.
Here how to do it on Windows :
https://filljoyner.com/2018/08/18/how-to-reset-visual-studio-code-on-windows/

Python 3 install error. This file does not have a program associated

I have encountered an error while try to run a python 3.6.4 script after upgrading from 2.7.
I had initial installed both python 2.7 and 3.6 but them deleted 2.7 because I had no use for it and i am not getting this error.
I have tried:
Reinstalling python 3.6.4
changing the install location of said install
Repairing the python 3.6 install
Error:
A Python script by itself is not an executable program. So if you want to run the script Evosim.py by just entering Evosim.py in the command line, the .py file ending needs to be associated with the Python interpreter. It seems that currently in your system this is not the case.
There are two ways to deal with your situation:
Start your script by entering python Evosim.py instead of only Evosim.py in the command line.
Fix the broken association of the .py file ending with the Python interpreter. The answers to this question migth help you with that.
Solution #1
Go to your registry by searching regedit.
Open category HKEY_CLASSES_ROOT. Select .py. If .py don't exists then make it by yourself.
Double click the Default. It will make a popup. Change its value to Python.IDLE and click OK. Make a new String key in .py naming Content Type with value text/plain.
Solution #2
If the above method don't works then just go ahead and reinstall your python (also uninstall Python Launcher). Your modules and files will be at their place.
You can now open .py files.
Running command prompt as an administrator resolved my issue, and able to execute my python script
1). Right click any python file
2). Click Open with then Choose another app
3). Click on More apps then Look for another app on this PC. It should open up file explorer
4). Select python.exe wherever it is located.
A sample path is C:\Users\<user>\AppData\Local\Programs\Python\Python38\python.exe for a user installation. A way to check this path is by typing where python into cmd; it will list all installations of Python.
Now the python.exe you chose is associated with all .py files and typing file.py should not give an error.

How to deploy Python to Windows users?

I'm soon to launch a beta app and this have the option to create custom integration scripts on Python.
The app will target Mac OS X and Windows, and my problem is with Windows where Python normally is not present.
My actual aproach is silently run the Python 2.6 install. However I face the problem that is not activated by default and the path is not set when use the command line options. And I fear that if Python is installed before and I upgrade to a new version this could break something else...
So, I wonder how this can be done cleanly. Is it OK if I copy the whole Python 2.6 directory, and put it in a sub-directory of my app and install everything there? Or with virtualenv is posible run diferents versions of Python (if Python is already installed in the machine?).
I also play before embedding Python with a DLL, and found it easy but I lost the ability to debug, so I switch to command-line plug-ins.
I execute the plug-ins from command line and read the STDOUT and STDERR output. The app is made with Delphi/Lazarus. I install others modules like JSON and RPC clients, Win32com, ORM, etc. I create the installer with bitrock.
UPDATE: The end-users are small business owners, and the Python scripts are made by developers. I want to avoid any additional step in the deployment, so I want a fully integrated setup.
Copy a Portable Python folder out of your installer, into the same folder as your Delphi/Lazarus app. Set all paths appropriately for that.
You might try using py2exe. It creates a .exe file with Python already included!
Integrate the python interpreter into your Delphi app with P4D. These components actually work, and in both directions too (Delphi classes exposed to Python as binary extensions, and Python interpreter inside Delphi). I also saw a patch for Lazarus compatibility on the Google Code "issues" page, but it seems there might be some unresolved issues there.
I think there's no problem combining .EXE packaging with a tool like PyInstaller or py2exe and Python-written plugins. The created .EXE can easily detect where it's installed and the code inside can then simply import files from some pre-determined plugin directory. Don't forget that once you package a Python script into an executable, it also packages the Python interpreter inside, so there you have it - a full Python environment customized with your own code.

Categories

Resources