I went through multiple SO questions but couldn't find a solution for my problem. I am new to Python and following is my setup,
VSCode: version 1.45
Python : 3.8.2
Pylint: 2.5.3
autopep8: 1.5.3
pycodestyle: 2.6.0
With the above setup, if I want to enforce PEP8 naming conversions what should I do? The VScode documentation provide how to configure pydocstyleargs but it's documentation does not cover naming conventions.
I also looked at the things autopep8 fixes and can configure via "python.formatting.autopep8Args", it doesn't fix/report things like classes not having pascal-case
As mentioned by #PyWalker2797, I tried installing pep8 and enable it by setting "python.linting.pep8Enabled": true. But VSCode doesn't recognise it even after a restart of the application.
I had the same problem.
If you read the documentation you will notice that the setting is not called pep8 but resides under the pydocstyle superset.
Thus, you have to use the following setting to enable checks on the variable conventions (and other stuff) from pep8:
"python.linting.pycodestyleEnabled": true,
Install pep8 and pylint using pip:
pip install pep8
pip install pylint
Then get your settings.json file, and add the line:
"python.linting.pep8Enabled": true
Related
I am using 18.04 Ubuntu with Anaconda.Recently i have trying to install OpenCV through conda-forge channel in the base environment. I did not install purposely any Python version and did not use any pip command either in base environment. Now, in the base environment, if execute just python, i get the same python version as system version and if execute python3 , i get the version installed by conda-forge. Please refer the screen shot. Python_on_Conda_base
I would like to know what is difference between python and python3 command?.What is should i keep in mind? basically i prefer the version 3.7.5 Python
.So, only the Python3 has uses different version. So, question what i should take note when i using python3 some_script.py? what is pros and cons of having this 2 version?
So far,i did not face any issues, but removed the conda-forge channel from Anaconda to avoid any conflicts. Any thoughts?
After posting this question, i have noticed python --version command gives Python 3.7.5 on Conda base environment and Ubuntu terminal (outside Conda)
You most likely have set an alias for python to point to the python3 binary.
Check this by typing type python, which will probably give you
python is aliased to ...
The crux here is that an alias will not be detected by which and as you revealed in the comments your which python returns the correct python version from your conda base environment, which makes an alias the most likely explanation, as PATH issues can be ruled out.
If above command does indeed reveal an alias, then check you .bashrc or similar file that you might have modified for a line alias python=.... Delete it, restart your terminal and everything should work normally
According to PEP 632, distutils will be formally marked as deprecated, and in Python 3.12, it will be removed. My product is soon going to support Python 3.10 and I don't want to put up with deprecation warnings, so I would like to remove references to distutils now. The problem is that I can't find good, comprehensive documentation that systematically lets me know that A in distutils can be replaced by B in modules C, D, and E. The Migration Advice in the PEP is surprisingly sketchy, and I haven't found standard documentation for distutils, or for whatever modules (such as setuptools?) that are required to replace distutils, that would let me fill in the gaps. Nor am I sure how to look at the content of the installed standard distribution (that is, the physical directories and files) in order to answer these questions for myself.
The "Migration Advice" section says:
For these modules or types, setuptools is the best substitute:
distutils.ccompiler
distutils.cmd.Command
distutils.command
distutils.config
distutils.core.Distribution
distutils.errors
...
For these modules or functions, use the standard library module shown:
...
distutils.util.get_platform — use the platform module
Presumably, that means that setuptools has either a drop-in replacement or something close to it for these modules or types (though I'm not sure how to verify that). So, for instance, perhaps setuptools.command.build_py can replace distutils.command.build_py. Is that correct? In any case, what about these?
distutils.core.setup
distutils.core.Extension
Furthermore, what am I supposed to make of the fact that setuptools does not appear under the modules or index list in the standard documentation? It is part of the standard distribution, right? I do see it under Lib/site-packages.
UPDATE 1: If setuptools is not currently part of the standard distribution, is it expected to become one, say, in Python 3.11 or 3.12? Are customers expected to install it (via pip?) before they can run a setup.py script that imports setuptools? Or is the thought that people shouldn't be running setup.py anymore at all?
Knowing how to replace distutils.core.setup and distutils.core.Extension is probably enough for my current needs, but answers to the other questions I've asked would be quite helpful.
UPDATE 2:
setuptools is indeed part of the python.org standard distribution, as can be determined by importing it from a freshly installed Python interpreter from python.org. The thing that was confusing me was that it is documented on a separate site, with a separate style, from python.org. However, as SuperStormer pointed out in the comments, some Linux distributions, such as Debian, don't install it by default when you install Python.
UPDATE 3:
This command:
Python-3.9.1/python -m ensurepip --default-pip
installs both pip and setuptools on Debian 10 on a Python installation freshly downloaded and built from python.org. Before the command is executed, pip is absent and setuptools cannot be imported.
On my Mac terminal i've installed python3 (3.7.6) using homebrew - e.g. if I issue command to upgrade via homebrew, it returns the up to date version:
$brew upgrade python3
Warning: python3 3.7.6_1 already installed
However when I ask for the version it tells me an older version (3.4.0) is installed:
$python3 --version
Python 3.4.0
So it's installed but not updated. I'd quite like 3.6 or later on my mac. I've tried uninstalling and reinstalling using homebrew, and had no luck. Wondering if anyone has any ideas?
//
Sidenote (1) - i'm relatively new to homebrew... $ brew doctor returns config scripts "outside your system or Homebrew directories" - not sure if this helps, and if this is the issue where to move them to.
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4m-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4-config
Sidenote (2) - 3.7.6 isn't the newest version out, but this is the latest version that homebrew will install. Is there any way to get an even newer version?
By chance i've come across the/a answer. I was editing .bash_profile and saw the very top says:
# Setting PATH for Python 3.4
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH
So I moved to this directory .../Versions/, found it had three subdirectories 3.3, 3.4, and 3.8, and updated to use:
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
And this seems to do the trick (to use the most recent). Although interestingly i've not came across 3.7.6... but is a bit redundant in my case since I can use the newer 3.8 version.
Quick fix:
You should be able to run the required version by running python3.7 instead of python3. You can set up an alias if you like with
"alias python=/usr/local/bin/python3.7"
where you put the desired binary on the RHS. This will create an alias for your current session. To always evoke this functionality, you can add this line to your bashrc file so this alias will work every time you log in to a new session
echo "alias python=/usr/local/bin/python3.7" >> ~/.bashrc
These commands were lifted from
https://opensource.com/article/19/5/python-3-default-mac
which explains some do and do-nots.
Alternative:
Also check out Python virtual environments, particularly virtualenv and virtualenvwrapper, which are great tools for separating out your Python working environments and allow you to set default Python version for each project separately, as well as managing any modules you pip install separately for each project. This is much cleaner in my opinion.
https://www.bogotobogo.com/python/python_virtualenv_virtualenvwrapper.php
When I'm opening a python file in emacs I get the following error message:
Flymake: Configuration error has occured while running (flake8 >..../xyz_flymake.py). Flymake will be switched OFF.
But on the other hand it seems I've configured all the modules needed for elpy to work properly:
Elpy Configuration
Virtualenv........: None
RPC Python........: 3.5.3 (/usr/bin/python3.5)
Interactive Python: /usr/bin/python3.5 (/usr/bin/python3.5)
Emacs.............: 24.5.1
Elpy..............: 1.10.0
Jedi..............: 0.10.2
Rope..............: 0.10.5
Importmagic.......: 0.1.7
Autopep8..........: 0.1.7
Syntax checker....: flake8 (/usr/local/bin/flake8)
You have not activated a virtual env. While Elpy supports this, it is
often a good idea to work inside a virtual env. You can use M-x
pyvenv-activate or M-x pyvenv-workon to activate a virtual env.
The directory ~/.local/bin/ is not in your PATH. As there is no active
virtualenv, installing Python packages locally will place executables
in that directory, so Emacs won't find them. If you are missing some
commands, do add this directory to your PATH.
Options
`Raised' text indicates buttons; type RET or click mouse-1 on a button
to invoke its action. Invoke [+] to expand a group, and [-] to
collapse an expanded group. Invoke the [Group], [Face], and [Option]
buttons below to edit that item in another window.
How can I resolve this issue?
It is unclear what the configuration error is. It's possible that you're running into one of many issues.
You seem to want to use Python 3.5, but there's no clear indicator of what version of Python Flake8 is running on. It could be that elpy is detecting a mismatch and refusing to use Flake8 when it won't provide you any useful information. (Flake8 must be installed on the same version of Python that the code is intended to run on.)
Elpy seems insistent that you use a virtualenv or that you add ~/.local/bin/ to your PATH. I would advise doing both.
You can create a virtualenv by doing virtualenv ~/.elpy-venv and activate it with source ~/.elpy-venv/bin/activate.
You can edit your Shell's configuration file (e.g., ~/.bashrc, ~/.bash_profile, ~/.zshrc, etc.) to do export PATH="$PATH:~/.local/bin".
I'm trying to install winshell under Python 3.3.0 / Windows 7.
(I should say that I have only a fuzzy notion of how package installing works, so my apologies if I'm making a basic blunder ... this stuff clearly is not really aimed at mere mortals).
What I did was: I opened a CMD window & navigated to the Python33 directory. I typed
pip install winshell
and got "...downloading winshell 0.6 zip followed by running setup.py egg_info for package winshell...
and then I got
python setup.py egg_info failed with error code 1 (in the log file)
I've tried googling generally and in here - most of the posts are moderately incomprehensible - to me at least. There are tentative suggestions in comments to an answer that suggest I'd need to install either pwin32 or win32con. And that pwin32 can't be installed with pip. But I haven't found a definitive 'how to' for installing winshell.
Before I go down either of those rabbit holes, is it correct that, in order to install & use winshell, do I need those modules? And please point me to the best, simple, instructions for doing that.
...
This is all for the purpose of getting the target path of a shortcut as in:
path = winshell.shortcut(filethatisashortcut).path
so as to kludge os.walk to follow shortcuts (Windows, remember!). If there's a more direct method - please advise.
You need to install the pywin32 module according to the docs:
Prerequisites & Compatibility
The module has been tested on versions of Python from 2.4 to 3.2. It may
also work on older (or newer) versions. You’ll need Python 2.5+ for context
manager support. It’s tested with the most recent pywin32 extensions, but
the functionality it uses from those libraries has been in place for many
versions.
(Also looking at the modules imported in the source files, you clearly need to install Python for Windows extensions (pywin32). Don't have access to a windows machine to test, but why don't you go by the book first.)