Sublime text command line Name error - sublimetext

Good Day,
I am trying to run command line stuff from Sublime text's console. Is that possible? doing stuff like "ls" doesn't work
ls
Traceback (most recent call last):
File "", line 1, in
NameError: name 'ls' is not defined

The Sublime Text console is actually the built-in Python interpreter, so it only accepts Python commands. You can use the os* module to interact with the operating system. The following commands will give you a directory listing:
import os
os.chdir('/path/to/something')
os.listdir('.')
Check out the Files and Directories* section of the docs for more commands.
* Sublime Text 2 uses Python 2.6, while ST3 uses version 3.3. If you're using ST3, just change the 2.6 in the URLs I gave to 3 and you'll get the correct documentation.

Related

How can I run pydoc when it doesn't appear to be on the PATH?

I am using MACOSX 10.12.3 and Python 3.52
I am running into issues when running pydoc in a bash script in python IDLE.
For example:
myFile = ‘/home/user/afile.py’
import subprocess
subprocess.run([‘pydoc’, ‘-w’, myFile])
Inevitably does not create the html file as would be expected.
On the other hand, when I run pydoc in the terminal
pydoc3 -w /home/user/afile.py
it always creates the wanted html file. But pydoc -w /home/user/afile.py generates an error
This is due to the fact that:
the python /home/user/afile.py contains a few print statements in python3 style. That is: print('blabla') instead of: print 'blabla' as would be the case on python2.
the bash script in IDLE does not load the correct pydoc. I should also mention that running subprocess.run([‘pydoc3’, ‘-w’, myFile]) generates an error, for example:
subprocess.run(['pydoc3', '-w', myFile]) File
"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py",
line 693, in run
with Popen(*popenargs, **kwargs) as process: File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py",
line 947, in init
restore_signals, start_new_session) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py",
line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'pydoc3'
Any one has a way to circumvent this please?
Question 1:
Regarding running the python 3 version of pydoc against python 2 code- That will not work. Pydoc will execute (import) the target module. You would need to use python 2 version of pydoc by modifying your path or using your favorite virtual environment tool.
Question 2:
If you can get a reference to your desired installation of python (by setting the path or activating a virtual environment), then you can handle missing or broken entry points with this syntax:
python -m pydoc -w myfile
You will also need to make sure myfile is in the current directory or on the PYTHONPATH or otherwise importable

Can't run a Python file in Windows command prompt [duplicate]

This question already has answers here:
How to run a python script from IDLE interactive shell?
(15 answers)
Closed 5 years ago.
I'm running Windows 7 64-bit with Python 3.4.1, 64-bit
cmd window
I've appended the PATH in system Environment Variable with ;C:\Python34 and saved, then gone into cmd and done the following, yet I keep getting an 'INVALID SYNTAX' message. Yes, I've searched the Q&A here and seen several threads with same problem, but haven't reached success trying their suggestions. As can be seen, I've tried 3 variations of the basic command "python ." Please help.
I think you're misunderstanding the idea.
If you want to execute a script "RUN_ME.py", run python RUN_ME.py directly in the command line. (type cmd into start and then python RUN_ME.py in the window you get)
If you want to type some lines of python and interpret them directly, type python without arguments. (or use the program shortcut you used here)
The mistake made here is the difference between the command line and the python REPL.
When you opened the terminal the way you did, probably by clicking on python terminal or whatever, you opened the python REPL (also available by executing python without arguments in command line), this is a place where you can execute code directly (no scripts). it used to be able to run python scripts as well but the command was phased out in python 3.x. Typically the REPL starts lines with >>>
To run a python script, you have to be in the command line and give the script as parameter to python, aka
python <script_name>. Getting the command line on windows can be done directly by typing cmd, or if you want to open it at a certain path, browse to the path you want in the file explorer and type cmd into the place where the path is displayed.
Okay, I understand now not to use 'python' plus the .py filename when already in the Python '>>>' prompt. Here's a simple try within Windows command prompt at navigating to the directory where the 'RUN_ME.py' file is located and attempting to run:
C:\>cd program files\trader workstation
C:\Program Files\Trader Workstation>cd ibridgepy
C:\Program Files\Trader Workstation\IBridgePy>python
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.getcwd()
'C:\\Program Files\\Trader Workstation\\IBridgePy'
>>> RUN_ME.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'RUN_ME' is not defined

Run a Python Script from a Mac Terminal

My file name is 'corr.py' located in the Downloads folder and I'm running python 2.7 in terminal in the correct working directory. When I run the command 'python corr.py' I get the error message below. What should I do?
>>> os.getcwd()
'/Users/Daniel/Downloads'
>>> python corr.py
File "<stdin>", line 1
python corr.py
^
SyntaxError: invalid syntax
>>> python3 corr.py
File "<stdin>", line 1
python3 corr.py
^
SyntaxError: invalid syntax
You're in a Python interpreter already. First type exit() to get back to the terminal. (Or just open a new terminal tab/window.) Then use python corr.py.

Sublime does not see env variables

When running sublime from desctop it does not see my PERL5LIB environment variable.
When running it from terminal - everithing is OK.
I set my variables in .bashrc and .bash_profile.
import os
>>> os.environ['SHELL']
'/bin/bash'
>>> os.environ['PERL5LIB']
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "./os.py", line 676, in __getitem__
KeyError: 'PERL5LIB'
this makes trouble with linting and build system - I can not link and build becase of perl does not see libraries.
How to fix env variable?
Bad news:
The Ubuntu desktop session is no longer affected by .profile.
Additionally bash doesn't parse .profile if either .bash_profile or
.bash_login exists.
You can work around:
Launching desktop application with an environment variable
You can add an environment variable to an application by editing its
.desktop file. For example, to run "digiKam" with the environment
variable APPMENU_DISPLAY_BOTH=1, find the corresponding
digikam.desktop file and add the setting of the variable, via the env
command, to the entry "Exec":
Exec=env APPMENU_DISPLAY_BOTH=1 digikam -caption "%c" %i
or do small script:
#!/bin/bash
source ~/.bashrc
/opt/sublime_text/sublime_text

Error when try installing budspencer theme for fish shell

My fish conf (.config/fish/config.fish)
set -e fish_key_bindings
set -U fish_key_bindings fish_vi_key_bindings
set fish_path $HOME/.oh-my-fish
set fish_theme budspencer
. $fish_path/oh-my-fish.fish
result in error: https://gist.github.com/LuizCarvalho/925de989c306828a410a
if I remove theme and sets result in:
desenvolvimento#dp-inf015:~$ fish
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
fish: Unknown command “fish_vi_key_bindings”
Standard input: begin; fish_vi_key_bindings ;end
^
in . (source) call of file “-”,
called on standard input,
in function “__fish_reload_key_bindings”,
called on line 209 of file “/usr/share/fish/functions/__fish_config_interactive.fish”,
in function “__fish_config_interactive”,
called on line 108 of file “/usr/share/fish/config.fish”,
in function “__fish_on_interactive”,
called on standard input,
in event handler: handler for generic event “fish_prompt”
If I uninstall fish, oh-my-fish and all file conf and install again, error keeps happening...
How I can solve this?
vi bindings are in an upcoming release, but not yet in a public one. That is why you get the error.
If you want to get vi bindings working and are willing to live on the edge, you can install the latest fish from trunk. If you are using homebrew, run brew install fish --HEAD. Or if you prefer to do it the old fashioned way, there's build instructions here.
Alternatively, if you understandably prefer to remain on the most recent public release, you should delete the fish_vi_key_bindings lines from config.fish.

Resources