Imagine the following case:
foo __init__.py foo __init__.py bar __init__.py baz.py
I'm seeing this error: [pylint] Unable to import 'requests' [import-error] & Unable to import 'requests_ntlm' but I can do a pip freeze and get the following output (be advised that I'm just showing relevant output): ,Also, try this-- from the command line, activate the virtual environment and run Python. Once you do that try to manually import "requests_ntlm". Did it succeed? With this, you could determine if the requests_ntlm was installed/compiled properly for the virtualenv you are using.,That being said, VSCode is pretty excellent once it is set up properly. Because it is smaller and simpler it quite a bit faster than PyCharm and more suited to low-resource machines.,Is there a preferred IDE for dealing with virtual envs? I really like many of the VS plugins but I am always open to trying a new IDE if its a more reasonable one.
request == 2018.11 .20 requests == 2.21 .0 requests - ntlm == 1.1 .0
#!/usr/bin/env python
import requests
from requests_ntlm import HttpNtlmAuth
username = '<DOMAIN>\\<UserName>'
password = '<Password>'
tfsApi = 'https://{myserver}/tfs/collectionName/_apis/projects?api-version=2.0'
tfsResponse = requests.get(tfsApi,auth=HttpNtlmAuth(username,password))
if(tfsResponse.ok):
tfsResponse = tfsResponse.json()
print(tfsResponse)
else:
tfsResponse.raise_for_status()
Ensure Pylint is installed for the above python environment,Solution 1: (configure workspace settings to point to fully qualified python executable):,TroubleshootingDebuggerVirtual EnvLintingFormattingAutocompleteJupyter,Configure the setting “pythonPath” to point to (previously identified) the fully qualified python executable.
- Scenario: You have a module installed, however the linter in the IDE is complaining about; not being able to import the module, hence error messages such as the following are displayed as linter errors:
..unable to
import 'xxx'..
- Open the workspace settings (settings.json)
- Identify the fully qualified path to the python executable (this could even be a virtual environment)
- Ensure Pylint is installed for the above python environment
- Configure the setting “pythonPath” to point to (previously identified) the fully qualified python executable.
"python.pythonPath": "/users/xxx/bin/python"
Solution: Add relevant command line args to ignore certain messages
Here we’ll assume you use a TAB character as indentation of python code instead of 4 or 2 spaces.
Pylint would generally display a warning for this with the error code W0312.
In order to disable this particular message all one needs to do is as follows in the settings.json file:
"python.linting.pylintArgs": [
"--disable=W0312"
],
python – How to create a for loop for OneHotEncoder – Code Utility,One, change the PYTHONPATH environment variable to include the directory above your module.,ruby – Rails db:setup aborted because wrong number of argument – Code Utility,export PYTHONPATH=$PYTHONPATH:/path/to/google_appengine_folder
I’m running PyLint from inside Wing IDE on Windows. I have a sub-directory (package) in my project and inside the package I import a module from the top level, ie.
__init__.py myapp.py one.py subdir\ __init__.py two.py
F0401: Unable to
import 'one'
Alternatively, edit ~/.pylintrc
to include the directory above your module, like this:
[MASTER]
init - hook = 'import sys; sys.path.append("/path/to/root")'
The solution to alter path in init-hook
is good, but I dislike the fact that I had to add absolute path there, as result I can not share this pylintrc file among the developers of the project. This solution using relative path to pylintrc file works better for me:
[MASTER]
init - hook = "from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
The problem can be solved by configuring pylint path under venv:
$ cat .vscode/settings.json
{
"python.pythonPath": "venv/bin/python",
"python.linting.pylintPath": "venv/bin/pylint"
}
The basic outline when you are not running from within the folder (ie maybe from pylint’s, though I haven’t used that) is:
topdir\ __init__.py functions_etc.py subdir\ __init__.py other_functions.py
[MASTER] init - hook = "from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc())) "