sublime text 2 build system: error 5 access is denied - sublimetext3

I used this as my python3.6 build system in Sublime Text 2:
{
"cmd": ["C:\\Users\\lol--\\AppData\\Local\\Programs\\Python\\Python36", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
When I try to build I get the Error: [WinError 5] access is denied
My Python3.6 exe is definitely in that directory!
What could be the problem and a solution?

As noted in this forum post on the Sublime Text forum, the problem is that you didn't specify as the first part of cmd the name of the python executable, you specified where it's stored. The first argument in cmd is the program to run, so you've told Sublime to run the directory and Windows is saying "No, you can't do that".
The error you get is different if you use shell_cmd instead and makes the problem you're having clearer. In either case the solution to the problem is to make sure that the first item is the name of the Python binary.

Related

Sublime Text - How to build using *NIX shell environment on a Windows machine?

I've Sublime Text installed on my Windows 10 machine. I'm trying to configure it so that when I build my code Sublime runs it through a Linux shell (bash, zsh, etc.) instead of the default Command Prompt.
Here's a simple Python code, trying to execute basic shell commands.
import os
os.system("pwd")
returns: 'pwd' is not recognized as an internal or external command, operable program or batch file.
I tried creating a simple test build-system file and modifying it like so:
{
"target": "exec",
"cmd": ["python3", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"},
"windows": {
"cmd": ["C:\\Cygwin\\bin\\python3.9.exe", "-u", "test.py"],
},
//
"variants":
[
{
"name": "Syntax Check",
"cmd": ["python3", "-m", "py_compile", "$file"],
"windows": {
"cmd": ["py", "-m", "py_compile", "$file"],
}
}
]
}
I put "target": "exec" line on top, and changed the cmd option so that it points to my Cygwin/bin directory. For some reason, it cannot work with the default "$file" option, so I changed it to be the files name:
/usr/bin/python3.9: can't open file '/cygdrive/c/Music/C:\Music\test.py': [Errno 2] No such file or directory
Now, I'm not sure how all this works, because the Python version on Cygwin (from apt-cyg) is 3.9.10, whereas I also have latest version 3.11.0 installed for Windows (which Sublime uses). So when I run test.py with os.system("which") on Cygwin, I get: 3.9.10 (naturally), but I get 3.11.0 when I build from Sublime.
Also, common commands like ls or which aren't working: sh: which: command not found, which is probably a pathing issue. This is as far as I could get on my own. I'm hoping someone here has a definite answer to this. Any further help is appreciated.

Python modules in Sublime textbook not working

I am trying to use Sublime text IDE for my Python projects. But after ensuring the build system, I am not able to run any program there. I am getting ModuleNotFoundError as soon as I import modules like NumPy, pandas.
Here is some useful information:
> import sys
> print (sys.executable)
/usr/local/bin/python3
The information on pip and Python are following
> which pip
/Users/harish/opt/anaconda3/bin/pip
> which python
/Users/harish/opt/anaconda3/bin/python
I have been using pip to install all the python modules.
I have searched extensively internet, I find no solution.
I am using MacBook Pro, macOS Catalonia. (my MPB is an old fart and Apple does not find it worthy to run BigSur)
As you can see from the outputs of sys.executable (run within Sublime) and which python (run in the shell), you are not using the same Python binary in both places. To set up Sublime to use the correct one where you installed your packages with pip, you'll need to create a new build system.
In Sublime, select Tools → Build System → New Build System… and change its contents to the following:
{
"cmd": [
"/Users/harish/opt/anaconda3/bin/python", "-u", "$file"
],
"working_dir": "$file_path",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Hit Save, which will automagically open up your Packages/User folder, and save it there as Python_Anaconda.sublime-build or something like that. Just don't name it Python.sublime-build, as a build system with that name already exists.
Now, select Tools → Build System → Python_Anaconda (or whatever you named it), and you should be able to run programs with the modules you installed previously.

UnicodeEncodeError: 'charmap' codec can't encode characters in position 35447-35448: character maps to <undefined> in SUBLIME [duplicate]

I have this Python3 code to attempt to read and print from a utf-8 encoded file:
f = open('mybook.txt', encoding='utf-8')
for line in f:
print(line)
When I build using Sublime Text 3 I get the following error:
UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 18: ordinal not in range(128)
However, it works file when I just execute my code in the terminal with python3.
My build configuration is
{
"cmd": ["/usr/local/bin/python3", "$file"]
, "selector": "source.python"
, "file_regex": "file \"(...*?)\", line ([0-9]+)"
}
If I change it to:
f = open('mybook.txt', encoding='utf-8')
for line in f:
print(line.encode('utf-8'))
Then it does print the utf-8 encoded byte string (I think that's what's happening).
b'Hello\n'
b'\xc2\xab\xe2\x80\xa2\n'
b'Goodbye'
But I also don't know how to go from this to printing the unicode characters on the screen...
Also, if I try changing this env variable as per A python program fails to execute in sublime text 3, but success in bash it still doesn't fix it.
The answer was actually in the question linked in your question - PYTHONIOENCODING needs to be set to "utf-8". However, since OS X is silly and doesn't pick up on environment variables set in Terminal or via .bashrc or similar files, this won't work in the way indicated in the answer to the other question. Instead, you need to pass that environment variable to Sublime.
Luckily, ST3 build systems (I don't know about ST2) have the "env" option. This is a dictionary of keys and values passed to exec.py, which is responsible for running build systems without the "target" option set. As discussed in our comments above, I indicated that your sample program worked fine on a UTF-8-encoded text file containing non-ASCII characters when run with ST3 (Build 3122) on Linux, but not with the same version run on OS X. All that was necessary to get it to run was to change the build system to enclude this line:
"env": {"PYTHONIOENCODING": "utf8"},
I saved the build system, hit ⌘B, and the program ran fine.
BTW, if you'd like to read exec.py, or Packages/Python/Python.sublime-build, or any other file packed up in a .sublime-package archive, install PackageResourceViewer via Package Control. Use the "Open Resource" option in the Command Palette to pick individual files, or "Extract Package" (both are preceded by "PackageResourceViewer:", or prv using fuzzy search) to extract an entire package to your Packages folder, which is accessed by selecting Sublime Text → Preferences → Browse Packages… (just Preferences → Browse Packages… on other operating systems). It is located on your hard drive in the following location:
Linux: ~/.config/sublime-text-3/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages
Once files are saved to your Packages folder (if you just view them via the "Open Resource" option and close without changing or saving them, they won't be), they will override the identically-named file contained within the .sublime-package archive. So, for instance, if you want to edit the default Python.sublime-build file in the Python package, your changes will be saved as Packages/Python/Python.sublime-build, and when you choose the Python build system from the menu, it will only use your version.
It works, thanks, the complete build system script for Sublime Text 3
Tool -> Build System -> New Build System
{
"shell_cmd": "python \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf8"}
}
Note if you use venv with S3 you will need to update the Python + Virtualenv.sublime-build resource file.
{
"target": "virtualenv_exec",
"shell_cmd": "python -u \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf-8"}
}

Getting SublimeText2 to compile Typescript

Really excited about using Typescript on the Mac however, even after a full day of troubleshooting, unable to get it to compile in SublimeText. Followed these directions (the first at the top) to install nodes and npm>
https://gist.github.com/isaacs/579814
Installed Typescript
sudo npm install -g typescript
Installed the syntax highlighting package for sublime
http://msopentech.com/blog/2012/10/01/sublime-text-vi-emacs-typescript-enabled/
Created a build file 'typescript.sublime-build as follows
{
"selector": "source.ts",
"cmd": ["tsc", "$file"],
"path": "/usr/local/bin",
"file_regex": "^(.+?) \\((\\d+),(\\d+)\\): (.+)$"
}
When I type $which node I get
/usr/local/bin/node
When I type $which tsc I get
/Users/<username>/local/bin/tsc
BUT, whenever I try to compile even the simplest .ts file in SublimeText the first effort message I get is
[Errno 2] No such file or directory
Can anyone suggest further troubleshooting steps?
I struggled with a little too. It seems the PATH is quite different when trying to run commands directly from the build system than the terminal, and this is a cause of problems.
What I did as a simple workaround was just set my command to run a Bash script, i.e. in the sublime.project file have the command as..
"cmd": ["./build.sh"]
.. and then in the build.sh script in my project folder simply run the compiler, i.e..
#! /bin/bash
tsc --target ES5 foo.ts
Obviously this assumes foo.ts pulls in all the other project files so they get compiled (or you could glob for the files on the command-line seeing as you're running a Bash command).
This might be a quick and simple solution for you.
You could do what my team mates do. Use Sublime Text for text editing with a grunt watch in the background compiling any files that change : https://github.com/basarat/grunt-ts

Problems with LESS Sublime Text Build System

On OS X 10.7.2, I created a small build system in Sublime Text 2 that will compile my LESS files into CSS for me, but it seems to be having a problem.
{
"cmd": ["/usr/local/lib/node_modules/less/bin/lessc", "-x", "$file", "$file_path/$file_base_name.css"],
"selector": ["source.less"]
}
I've installed Node.js v0.6.6 using the standard OS X installer package, and installed less v1.1.6 using npm into the /usr/local/lib/node_modules folder. Switching to my build system works fine, but when I attempt to run the build I get the following error message:
[Finished]env: node: No such file or directory
Running the command from the terminal works perfectly fine, it's just Sublime that is taking issue.
Another way to solve this is to install LESS globally, as it looks like you've already done:
npm install -g less
Then pass shell=true as a variable in the build script:
{
"shell" : true,
"cmd": ["lessc", "-x", "$file", "$file_path/$file_base_name.css"],
"selector": "source.css.less"
}
That runs the lessc command in the terminal in a way you'd expect.
While I am still unsure as to why there is a difference between Sublime Text 2 and running the build system in the terminal, I fixed the issue I was encountering by explicitly adding the value of $PATH to my build system.
Acting on the documentation provided on the Sublime Text Help page, I set up my build system to be the following:
{
"cmd": ["/usr/local/lib/node_modules/less/bin/lessc", "-x", "$file", "$file_path/$file_base_name.css"],
"selector": "source.css.less",
"path": "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin: No such file or directory"
}

Resources