How to get Python 3.4 on Sublime Text 3? - python

Does anyone have a step by step process for a beginner to get the latest version of Python (3.4) to work on Sublime Text 3? I tried adding Python 3 as another build but I don't think i added it correctly (the instructions were for how to add it for Sublime Text 2) because I cannot build my function when I set it to Python 3 on Sublime Text 3. Only the basic Python build version is working. How can I get Python 3.4 to work? Thanks really need help immediately

Goto Tools > Build > New Build System and enter the following.
{
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf8",
"path": "/Library/Frameworks/Python.framework/Versions/3.4/bin/" }
Save the file and restart Sublime Text. If it still doesn't work, check if the 'path' is correct in your case.

Tools > Build System > New Build System..
Replace this code
{
"shell_cmd": "make"
}
with this
{
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
}
/usr/local/bin/python3 ==> python.exe path in your system
then save with a name.sublime-build. It will appear in build system. select the build system and run the python code by pressing Ctrl + B

Select the menu Tools > Build > New Build System and enter the following:
{
"cmd": ["python3", "$file"]
, "selector": "source.python"
, "file_regex": "file \"(...*?)\", line ([0-9]+)"
}
After that, save it to the following (Mac-specific) directory: ~/Library/Application Support/Sublime Text 3/Packages/User
That's all there to it.

Related

New and trying to get python set up with Sublime Text [duplicate]

I want to configure Sublime Text 3 to build Python 3, but I don't seem to understand how the builds work. Many tutorials have told me to make a build file containing code such as:
{
'cmd': ['/usr/bin/python3', '-u', '$file'],
'file_regex': '^[ ]*File "(…*?)", line ([0-9]*)',
'selector': 'source.python'
}
and save it as a file called Python.sublime-build or python3.sublime-build (much of the information I found was conflicting). One tutorial suggested creating a new folder in the ST3 Packages folder called Python and add the build file in there, whilst other tutorials suggested leaving it in the folder called User.
One tutorial explained how I had to change the Environment Variable path on my operating system to get it to work. That didn't seem to help either.
I added a folder Python to Packages (since it wasn't there already) and added in a build file with the name Python.sublime_build which featured only the code I posted above in it. Now when I attempt to run Sublime Text it gives me this error:
Error trying to parse build system:
Expected value in Packages\Python\Python.sublime-build:2:5
The reason you're getting the error is that you have a Unix-style path to the python executable, when you're running Windows. Change /usr/bin/python3 to C:/Python32/python.exe (make sure you use the forward slashes / and not Windows-style back slashes \). Once you make this change, you should be all set.
Also, you need to change the single quotes ' to double quotes " like so:
{
"cmd": ["c:/Python32/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
The .sublime-build file needs to be valid JSON, which requires strings be wrapped in double quotes, not single.
Steps to Make Sublime Text a Python IDE (Windows)
Tested successfully on Sublime Text 3. Assuming Sublime Text and package control are already installed . . .
Install Python (python.org) and pay attention to where it is installed or choose a simple location like the C drive, agreeing to remove character limit at the end of the installation.
Install package SublimeREPL (Cntrl + Shift + P, Package Control - Install Package, SublimeREPL, Enter).
Go to Preferences, Package Settings, SublimeREPL, Settings - User.
Paste in the following, updating the file path to your python installation folder, as needed. You may customize these and choose whatever syntax you like (last line) but I prefer my output in plain text.
{
"default_extend_env": {"PATH":"C:\\Program Files\\Python36\\"},
"repl_view_settings": {
"translate_tabs_to_spaces": false,
"auto_indent": false,
"smart_indent": false,
"spell_check": false,
"indent_subsequent_lines": false,
"detect_indentation": false,
"auto_complete": true,
"line_numbers": false,
"gutter": false,
"syntax": "Packages/Text/Plain text.tmLanguage"
}
}
Save and close the file (SublimeREPL.sublime-settings).
Go to Tools, Build System, New Build System.
Replace all existing text with the following:
{
"target": "run_existing_window_command",
"id": "repl_python_run",
"file": "config/Python/Main.sublime-menu"
}
Cntrl + S or save as "C:\Users[username]\AppData\Roaming\Sublime Text 3\Packages\User\SublimeREPL-python.sublime-build" updating username or path as needed. This should be wherever your settings and builds are stored by Sublime Text.
Go to Tools, Build System, select SublimeREPL-python.
All done--now to test. Open or create a simple python file, having a *.py extension and save it wherever desired.
Make sure the file is open and selected in Sublime Text. Now, when you press Cntrl + B to build and run it, it will open another tab, titled "REPL [python]", executing and displaying the results of your python code.
If you would like to go a step further, I highly recommend making the follow changes, to allow Sublime to reload your executed python in the same window, when you press Cntrl+B (Build), instead of it opening a new tab each time:
Add the following line in the "repl_python_run" command in (Preferences, Browse Packages) SublimeREPL\config\Python\Main.sublime-menu, right before the "external_id": "python" argument:
"view_id": "*REPL* [python]",
and then to change the line:
if view.id() == view_id
into:
if view.name() == view_id
in SublimeREPL\sublimerepl.py.
If you are using PyQt, then for normal work, you should add "shell":"true" value, this looks like:
{
"cmd": ["c:/Python32/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"shell":"true"
}
Run Python Files in Sublime Text3
For Sublime Text 3,
First Install Package Control:
Press Ctrl + Shift + P, a search bar will open
Type Install package and then press enter
Click here to see Install Package Search Pic
After the package got installed. It may prompt to restart SublimeText
After completing the above step
Just again repeat the 1st and 2nd step, it will open the repositories this time
Search for Python 3 and Hit enter.
There you go.
Just press Ctrl + B in your python file and you'll get the output.
Click here to see Python 3 repo pic
It perfectly worked for me. Hopefully, it helped you too.
For any left requirements, visit https://packagecontrol.io/installation#st3 here.
Steps for configuring Sublime Text Editor3 for Python3 :-
Go to preferences in the toolbar.
Select Package Control.
A pop up will open.
Type/Select Package Control:Install Package.
Wait for a minute till repositories are loading.
Another Pop up will open.
Search for Python 3.
Now sublime text is set for Python3.
Now go to Tools-> Build System.
Select Python3.
Enjoy Coding.
Version for Linux. Create a file ~/.config/sublime-text-3/Packages/User/Python3.sublime-build with the following.
{
"cmd": ["/usr/bin/python3", "-u", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python"
}
And to add on to the already solved problem, I had installed Portable Scientific Python on my flash drive E: which on another computer changed to D:, I would get the error "The system cannot find the file specified". So I used parent directory to define the path, like this:
From this:
{
"cmd": ["E:/WPy64-3720/python-3.7.2.amd64/python.exe", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
To this:
{
"cmd": ["../../../../WPy64-3720/python-3.7.2.amd64/python.exe","$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
You can modify depending on where your python is installed your python.
first you need to find your python.exe location, to find location run this python script:
import sys
print(sys.executable)
Then you can create your custom python build:
{
"cmd": ["C:\\Users\\Sashi\\AppData\\Local\\Programs\\Python\\Python39\\python.exe", "-u", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python"}
You can change the location, In my case it is C:\Users\Sashi\AppData\Local\Programs\Python\Python39\python.exe
Then save your new build. Don't change the file extension while saving.
I'd like to add just one point to the accepted answer:
when you edit the cmd portion of the snippet below, make sure to add the file address (with forward slash) where python is kept on your computer.
{
"cmd": ["c:/Python32/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
How to know where python is installed on your system? Two ways for windows users:
Open Command prompt and do the following query: where python
If it shows the path to python.exe, copy and paste it with /. If it shows some error, then follow process below:
Go to start -> Search for python shortcut (not IDLE) -> Right Click -> More -> Open file location -> Right click the shortcut -> Properties -> Target -> Path is now visible -> Copy and paste it in the field above.
Here is a very simple Python Sublime Text build system that works when python scripts are invoked with py file_name.py.
Just create py.sublime-build by Tools > Build System > New Build System and add the contents below:
{
"cmd": ["python3", "$file"]
}
You can select it in Sublime Text editor by going to Tools > Build System > py and building with Ctrl + b.
Note: If your filesystem doesn't python3 than you need to provide path/to/python3 and it should work.

Python 3.5: Sublime Text Won't Recognize 3rd Party Modules...How to Fix?

(I understand variations of this question have been asked before, but not specifically with Python 3+ and Sublime Text 3, and I tried the solutions but none of them worked.)
Anyhow: I'm using Python 3.5. I'm trying to use a 3rd party module - Scrapy - in Sublime Text. While the module works in IDLE, it does not work in Sublime.
I tried redirecting my PYTHONPATH but that still didn't work. My syntax-specific settings for Python are:
{
"path": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"word_wrap": true,
"env": {
"PYTHONPATH": "/Library/Frameworks/Python.framework/Versions/3.5/bin"
}
I've run into this.
In your case Sublime Text 3.x needs a new build system that needs the "path" and the "cmd" defined in the new build system to correctly recognize both the location of the modules and what python command string you want to build with.
For Python 3.7 on OSX 10.14.2 I used the build file below. I assume the same will work with 3.5 or any 3.x version if modified by replacing the 3.7's with 3.5's. If you install a new version of python you will need a new build system in sublime as well.
Under tools>build system>new build system add a file containing the settings below and save it.
{
"path": "/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"cmd": ["/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Switch to it using tools > build with.
What you need is a build system, not syntax-specific settings. Select Tools -> Build System -> New Build System... and change the contents to the following:
{
"path": "/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
"cmd": ["/Library/Frameworks/Python.framework/Versions/3.5/bin/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Save the file as Packages/User/Python3.5.sublime-build where Packages is the folder opened by selecting Preferences -> Browse Packages... (when you hit Save after editing the new build system, it should automatically point you to Packages/User).
To use the build system, select Tools -> Build System -> Python3.5, then hit CtrlB (Windows, Linux) or ⌘B (OS X) when your .py file is focused.

How do I run python 3.4 on sublime text 2?

This is what my python build looks like:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
I've read that I need to change what's in the "python" part of "cmd":, but I can't find what to change it to. I've seen one video where a guy made it look really easy by taking the path from the terminal. Others say to add a "path": blah blah blah. It always seems to be for Windows computers.
I've tried so many things and I really don't know what to change to make sublime text 2 to run python. Also does it make a difference if I'm using a mac vs windows?
cmd needs to be changed to the path of the python 3 executable. By default, the installer places it in ~/Library/Frameworks/Python.framework/Versions/3.4/bin/python3. So, if your mac username is Anthony, you will need to change your build like so:
{
"cmd": ["/Users/Anthony/Library/Frameworks/Python.framework/Versions/3.4/bin/python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Note: When running python 3 from the terminal, you are able to use the shortcut command python3. This is because an ALIAS was set up in your .bash_profile when python was installed. However, Sublime Text doesn't read your .bash_profile, so you must specify the full path to python.

getting sublime text 3 to use anaconda python

So I've installed anaconda to a directory I have privileges for but I can't get sublime text 3 to recognise that the shell is now using anaconda python:
>which python
/local/home/USER/Apps/anaconda/bin/python
when I build with sublime launched from the same shell:
import astropy
print astropy.__file__
it gives a different directory: /soft/python-SL7/lib/python2.7/site-packages/astropy/init.pyc
My .tcshrc file reads:
setenv PATH /local/home/USER/Apps/anaconda/bin:${PATH}
alias subl /local/home/USER/Apps/sublime_text_3/sublime_text
My .bashrc (not that it should be using it) reads:
export PATH="/local/home/sread/Apps/anaconda/bin:$PATH"
Any ideas?
The easiest way is to create a new build system that points to your Anaconda installation. Create a new file in Sublime with JSON syntax and the following contents:
{
"cmd": ["/local/home/USER/Apps/anaconda/bin/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Save the file in your Packages/User directory (should be ~/.config/sublime-text-3/Packages/User) as Anaconda.sublime-build. Finally, select Tools → Build System → Anaconda, and when you hit CtrlB in a Python file it should now run using Anaconda.
If you want to set up SublimeREPL to use Anaconda with IPython in Sublime, you can follow the instructions here to set up the proper menu option (altering the path to suit your environment, of course), and my gist here for setting up SublimeREPL for IPython 4 and Jupyter.
The other answer is correct, but you can also have a per project setting by editing the project file and adding this:
"build_systems":
[
{
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"name": "Anaconda Python Builder",
"selector": "source.python",
"shell_cmd": "\"python3\" -u \"$file\""
}
],
This also has the advantage of not leaving too many build systems in the build menu.

Sublime Text shows nothing on Python build

I'm learning Python in recent days and discovered I can use Sublime Text as Python text editor. However I always runned my programs at the "C:\Python34" folder. Now I tried to put my codes in another folder, out of this one, but I don't know why it's not working. Work just at the "Python34" folder...
The console status only shows "Building" and nothing...
My "Python.sublime-build" file:
{
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"encoding": "utf8"
}
Sublime Text 2; Python 3.4; Windows 8.1
Any idea?
Try make sure you have Python in your system path:
Windows key + Pause/Break key to shortcut to System.
Click on Advanced System Settings.
Scroll down in System Variables until you find "Path", click "edit"
Look for C:\Python34 in the string; if it's there don't worry, if not, add it in as follows:
someDirectory\lastItem;C:\Python34. Seperate with semi-colon. (for windows).
Now, you can change your Python.sublime-build file as follows:
{
"cmd": ["C://Python34/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
If needed, change the directory for Python, or change "34" to whichever version you use. Should do the trick.
EDIT: Feel free to leave in your encoding, I just copy/pasted my sublime-build.

Categories