How do I run python 3.4 on sublime text 2? - python

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.

Related

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.

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.

Sublime Text 2 Python Issue. Python in Path and can be compiled via cmd

Hello I am someone new to Python and am trying to get started.
Problem:
I have Sublime Text 2 and am having problems running some simple code.
I have:
Python Installed # C:\Program Files\Python\Python 278
Work Folder with Code # C:\Users\Computer\Desktop\Learning Python
Code is: ex1.py
I have added Python to my Environment Variables (both User variables and system variables).
My sublime is set for Python.
Here is my code:
print "Yo"
When I try to build I get:
[Error 2] The system cannot find the file specified
[cmd: [u'g++', u'C:\\Users\\Computer\\Desktop\\Learning Python\\ex1.py', u'-o', u'C:\\Users\\Computer\\Desktop\\Learning Python/ex1']]
[dir: C:\Users\Computer\Desktop\Learning Python]
[path: ...;C:\Program Files\Python\Python 278]
[Finished]
I can run python from powershell and cmd.
http://gyazo.com/cfa64a39730b3aefce6daf530a099453
Again I must stress that typing python in my cmd will start the python interpreter
I even changed Python.sublime-build
"cmd": ["C:\Program Files\Python\Python 278\python.exe", "-u", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python"
and
"cmd": ["C:\Program Files\Python\Python 278\python.exe", "-u", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python"
and originally it was
"cmd": ["python", "-u", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.python"
Please help. I have spent over 7 hours on this problem and I am sure I just missed something stupid.
Thank you so much for your time and help!
Okay I am mega stupid.
I saw this:
http://gyazo.com/6b3d484b8d00831b631bacc73fe6825a
and thought I set my build system to Python.
Nope!
Please Tools->Build System->Python

How to get Python 3.4 on Sublime Text 3?

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.

Python settings in Sublime Text 2

When I press ctrl+B in SB2 in the console I get ImportError: No module named site.
How to fix it?
First make sure that you saved the file with .py extension and then try to run again. You also need to check that the Python in your .sublime-build is correct. For this look at %APPDATA%\Sublime Text 2\Python\Python.sublime-build file. This file should have something like this:
{
"cmd": ["C:\\python27\\python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
This is equivalent to doing the following on the command line, check that you can do:
python -u C:\your_path\your_script.py
If this doesn't work from the command line it also wont from sublime.

Categories