When I open my Python files in Sublime and delete simple things like : at the end of def myFunction():, then I expect the linter to add a red circle in the gutter. But I see nothing in the gutter.
I notice at the bottom of the Sublime window it says "pyflakes(erred)"
Installing the dependencies
# Sublime v 3.1.1
# Sublime package install SublimeLinter
# Sublime package install SublimeLinter-pyflakes
pip3 install pyflakes
which pyflakes
# /Users/macbook/Desktop/my_virtual_env/bin/pyflakes
Trying to tell my linter the path to use in "MyProj.sublime-project" settings
{
"folders":[
{
"path": "."
}
],
"SublimeLinter.linters.pyflakes.python": "/Users/macbook/Desktop/my_virtual_env/bin/python3"
}
UPDATE: Sublime console output upon loading views.py
SublimeLinter: #10 linter.py:907: 'pyflakes' is linting 'views.py'
SublimeLinter: #10 python_linter.py:42: pyflakes: wanted python is 'None'
SublimeLinter: #10 python_linter.py:93: pyflakes: trying to use globally installed pyflakes
SublimeLinter: #10 python_linter.py:101: WARNING: cannot locate 'pyflakes'. Fill in the 'python' or 'executable' setting.
These settings go under the key settings. E.g.
{
"folders": [
{
"path": "."
},
],
"settings": {
"SublimeLinter.linters.pyflakes.python": "..."
}
}
Related
Okay, I've looked through a bunch of python venv with sublime text questions, and I'm pretty sure this issue is due to the specifics of venv on windows.
I'm on Windows, using Python 3.10, and the virtualenv package to manage my virtual environments.
I'm trying to set up a custom build in a Sublime project file that does the following:
activate the venv for the local project
echos the VIRTUAL_ENV to the shell to show the correct venv has been activated
I've been having issues with getting both into one build command, so here's the current array with the two steps as seperate builds:
"build_systems":
[
{
"name": "activate",
"cmd": "$project_path/venv/Scripts/activate.bat",
"shell": true
},
{
"name": "Current VENV?",
"cmd": "echo %VIRTUAL_ENV%",
"shell": true
},
]
Currently, when I run the activate build, I get the following:
The system cannot find the path specified.
[Finished in 80ms with exit code 1]
[cmd: C:\Users\kreeh\Repos\project/venv/Scripts/activate.bat]
[dir: C:\Users\kreeh\Repos\project]
If I run C:\Users\kreeh\Repos\project/venv/Scripts/activate.bat in a separate cmd.exe window, it correctly activates the venv, and when I print the %VIRTUAL_ENV% var, it correctly returns the venv location.
C:\Users\kreeh>C:\Users\kreeh\Repos\project/venv/Scripts/activate.bat
(venv) C:\Users\kreeh>echo %VIRTUAL_ENV%
C:\Users\kreeh\Repos\project\venv
I assume this is an issue with how the Sublime Text build system is handling the windows path formatting. If I try and utilize the working directory param, it doesn't work, because the cmd.exe doesn't do relative paths nicely.
{
"name": "activate",
"cmd": "venv/Scripts/activate.bat",
"working_dir": "${project_path}",
"shell": true
},
returns
'venv' is not recognized as an internal or external command,
operable program or batch file.
[Finished in 60ms]
So, is there a way to have the Sublime Build system handle the windows path correctly, or is there a way to use a relative path in the cmd?
#MattDMo pointed out the flaw in my logic, which is that the venv activation doesn't actually do anything in and of itself -- it changes the python interpreter used for future commands in that prompt window. As such, it's kind of a useless thing for a build system. Instead, I added a venv-specific pip install and build commands so far.
{
"build_systems":
[
{
"name": "pip install",
"cmd": "${project_path}/venv/Scripts/pip3.exe install -r requirements.txt ",
"working_dir": "${project_path}",
"shell": true
},
{
"name": "VENV Build",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"cmd": "${project_path}/venv/Scripts/python.exe $file",
"shell": true,
},
],
"folders":
[
{
"follow_symlinks": true,
"path": "."
}
],
One thing to note, as a Windows user, I had to add the follow_symlinks=true to the folders list -- this is because the way venv works on windows (or at least on MY install), there's not an actual python.exe in that venv folder, it's a symlink.
I'm trying to compile a .sol with py-solc-x.
I downloaded the library with pip install py-solc-x but still, vscode doesn't recognize it.
please help me fix this.
The massage after pip install
The code
You create virtual environment and then install it. I get alot of imports error in pycahrm and vscode for packages.
python3 -m venv venv
source venv/bin/activate
pip3 install py-solc-x
Also the way you import package is not correct. this is how you should setp:
from solcx import compile_standard, install_solc
# whichever version u want to use
install_solc("0.8.0")
You have installed the solcx in the global python310 environment, please check which python interpreter you have selected from the bottom-left on the VSCode.
I'm working on the same tutorial and ran into the same issue as you. I followed #Steven-MSFT's tip and got the code to work. Take a look:
from solcx import compile_standard, install_solc
_solc_version = "0.6.0"
install_solc(_solc_version)
with open("./SimpleStorage.sol", "r") as file:
simple_storage_file = file.read()
# Compile our solidity
compiled_sol = compile_standard(
{
"language": "Solidity",
"sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
"settings": {
"outputSelection": {
"*": {"*": ["metadata", "evm.bytecode", "evm.sourceMap"]}
}
},
},
solc_version=_solc_version,
)
print(compiled_sol)
Then I ran python3 deploy.py and it successfully outputted the ABI JSON object!
I also founded this issue. The problem is Python is install globally but site package is in user appdata, in your case "C:\users\kin...\python310\site-packages".
i had uninstalled python and deleted python310 folder in user appdata then installed python and packages again, this time in vscode python extnsion setting page tick "Global module installation".
i hope this work for you too.
I want to run Pylint or any equivalent while using Jupyter-Notebook. Is there a way to install and run Pylint this way?
pycodestyle is an equivalent of pylint for Jupyter Notebook which is able to check your code against the PEP8 style guide.
First, you need to install the pycodestyle in jupyter notebook by typing this command,
!pip install pycodestyle pycodestyle_magic
Run this command in a cell of jupyter notebook.
After successful installation, you have to load the magic in a Jupyter Notebook cell like this,
%load_ext pycodestyle_magic
Then, you have to use pycodestyle in a cell in which you want to investigate your code against PEP8 standards.
Below are some examples for more and clear understanding,
%%pycodestyle
a=1
Output: pycodestyle will give you this message,
2:2: E225 missing whitespace around operator
Another example,
%%pycodestyle
def square_of_number(
num1, num2, num3,
num4):
return num1**2, num2**2, num3**2, num4**2
Output:
2:1: E302 expected 2 blank lines, found 0
3:23: W291 trailing whitespace
I suggest you consider the nbQA tool:
pip install nbqa pylint
nbqa pylint my_notebook.ipynb
Besides pylint, nbqa makes it easy to run several other formatter and linter tools and is easy to integrate into your development workflow via their dedicated pre-commit hooks.
To answer the question more specifically in regards to pylint. One relatively simple way to achieve that in a development / ci environment (i.e. command line) is to convert the notebook to Python and then run the linting.
Let's assume you have notebooks in the ./notebooks folder and you have the jupyter and pylint command in the path, you could run the following:
jupyter nbconvert \
--to=script \
--output-dir=/tmp/converted-notebooks/ \
./notebooks/*.ipynb
pylint /tmp/converted-notebooks/*.py
You might want to configure pylint, as the notebook style is slightly different to a general Python module.
Some rules that you might want to disable:
pointless-statement
expression-not-assigned
trailing-newlines
wrong-import-position
redefined-outer-name
invalid-name
It also appears that the maximum number of characters in a cell (before horizontal scrolling) is 116 but that might depend on other factors.
(These options can for example be configured using the --max-line-length and --disable pylint arguments, or via the .pylintrc file)
The JupyterLab extension jupyterlab-lsp supports pylint (but pylint is disabled by default):
https://github.com/python-lsp/python-lsp-server/issues/171#event-6236223765
pip install jupyterlab-lsp
pip install 'python-lsp-server[all]'
Here is my config for the LanguageServer tab under Settings => Advanced Settings Editor, enabling pylint:
{
"language_servers": {
"pyright": {
"serverSettings": {
"python.analysis.useLibraryCodeForTypes": true
}
},
"pylsp": {
"serverSettings": {
"pylsp": {
"plugins": {
"pydocstyle": {
"enabled": true
},
"pyflakes": {
"enabled": false
},
"flake8": {
"enabled": true
},
"pylint": {
"enabled": true
}
}
}
}
}
}
}
In case you opt for using nbqa but you happen to have notebooks using pyspark as framework (instead of python), the following command will fail to recognize your notebooks:
nbqa pylint **/*.ipynb
The reason is that .ipynb files using pyspark have this metadata in the body:
"metadata": {
"name": "pyspark"
}
which prevents nbqa for recognizing it as python type. The solution is to simply substitute the value of "pyspark" with "python", here is a shell script that does it (you might need to install jq):
for i in $(find . -type f -name "*.ipynb");
do jq '.metadata.language_info.name="python"' "$i" > "$i".ipynb;
nbqa pylint "$i".ipynb -f colorized --fail-under=7;
rm "$i".ipynb;
done;
I'm trying to get autocompletion working in Sublime Text 3 via the Anaconda plug-in. So far I've been successful getting autocompletion working with the standard python libraries but not for Django.
My sublime project file looks like this:
{
"folders": [
{
"follow_symlinks": true,
"path": "."
}
],
"settings": {
"python_interpreter": "/Users/user/.virtualenvs/project/bin/python",
"suppress_word_completions": true,
"extra_paths":
[
"/Users/user/.virtualenvs/project/lib/python2.7/site-packages"
],
"anaconda_debug": true,
},
"build_systems":
[
{
"name":"Virtualenv 2.7 Project",
"shell_cmd": "/Users/user/.virtualenvs/project/bin/python -u \"$file\"",
"path": "/Users/jamiehush/.virtualenvs/project/bin",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
]
}
I'm also running "subl" from a terminal while inside a virtual environment.
You shouldn't need any special extra_path to make autocompleting work with Django. Nothing make Django special, anaconda should be able to autocomplete whatever is visible by your configured python interpreter.
Make sure that the virtual environment in project has a copy of Django installed on it. If you have virtualenwrapper installed should be as easy as:
$ workon project
$ python
import django
If you have Django in your virtualenv, is possible that the anaconda JsonServer was started before you installed the library and it's not able to see it. Restart your Sublime Text 3 and try again.
In case that you still have problems, send an email to the anaconda's mailing list or open an issue in the Github project (https://github.com/DamnWidget/anaconda/issues) indicating your operating system, ST3 build and Python version that you are using so we can help you further.
Basically, I've installed Sublime Text 2 to write in Python.
I then installed Package control and via package control I search "SublimeREPL" and I install the package, however even after installing, when I select Python through Tools > SublimeREPL > Python > Python, I get the error:
WindowsError(2, 'The system cannot find the file specified.')
Any help please? I'm pretty new to this.
Go to preferences -> Keybindings - User
and paste this. Make sure there are only one set of [] in your file, if you have custom keybinds set already then add a , after your last } then paste everything but the [] at the beginning and end after your ,.
[
{ "keys": ["ctrl+shift+r"], "command": "repl_open",
"caption": "Python",
"mnemonic": "p",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python", "-i", "-u","$file"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python"
}
}
]
Save and quit Sublime Text.
Follow these instructions
How to add to the pythonpath in windows 7?
You should now be able to run your current file in repl with crtl+shift+r
Open sublime text and create a new file. Save it as hello.py
Type:
print('Hello World')
Save then hit ctrl-shift-r
See if that works