I am using the following setup
macOS v10.14 (Mojave)
Python 3.7.1
Visual Studio Code 1.30
Pylint 2.2.2
Django 2.1.4
I want to use linting to make my life a bit easier in Visual Studio Code. However, for every import I have states "unresolved import". Even on default Django imports (i.e. from django.db import models).
I presume it is because it is not seeing the virtual environment Python files.
Everything works just fine, but it's starting to get annoying.
The interpreter choices I have are all system versions of Python. It does not seem to see my virtual environment Python at all (it is not in the same directory as my workspace, so that part makes sense).
If I set up the python.PythonPath in the settings.json file, it just ignores it and does not list my virtual environment path as an option. I also tried setting it up in my global Python settings, but it also does not show up.
Is there a quick fix to get it working?
The accepted answer won't fix the error when importing own modules.
Use the following setting in your workspace settings .vscode/settings.json:
"python.autoComplete.extraPaths": ["./path-to-your-code"],
Reference: Troubleshooting, Unresolved import warnings
In your workspace settings, you can set your Python path like this:
{
"python.defaultInterpreterPath": "/path/to/your/venv/bin/python",
}
Alternative way: use the command interface!
Cmd/Ctrl + Shift + P → Python: Select Interpreter → choose the one with the packages you look for:
This issue has already been opened on GitHub:
Python unresolved import issue #3840
There are two very useful answers, by MagnuesBrzenk and SpenHouet.
The best solution for now is to create a .env file in your project root folder. Then add a PYTHONPATH to it like this:
PYTHONPATH=YOUR/MODULES/PATH
And in your settings.json add:
"python.envFile": ".env"
When I do > reload window that fixes it.
Reference: Python unresolved import issue #3840, dkavraal's comment
None of the solutions worked except this one. Replacing "Pylance" or "Microsoft" in the settings.json solved mine.
"python.languageServer": "Jedi"
You need to select the interpreter associated with the virtual environment.
Click here (at the bottom status bar):
And just select the virtual environment you are working with. Done.
Sometimes, even with the interpreter selected, it won't work. Just repeat the process again and it should solve it.
If you have this code in your settings.json file, delete it:
{
"python.jediEnabled": false
}
If you are more visual like myself, you can use the Visual Studio Code configurations in menu File → Preferences → Settings (Ctrl + ,). Go to Extensions → Python.
In the section Analysis: Disabled, add the suppression of the following message: unresolved-import:
I was able to resolved this by enabling jedi in .vscode\settings.json
"python.jediEnabled": true
Reference from https://github.com/Microsoft/vscode-python/issues/3840#issuecomment-456017675
I wonder how many solutions this problem have (or have not), I tried most of the above, nothing worked, the only solution that worked is to set the python language server to Jedi, instead of Microsoft in the settings.json file:
"python.languageServer": "Jedi"
None of the previous answers worked for me. Adding both of the lines below to my settings.json file did, however.
"python.analysis.disabled": [
"unresolved-import"
],
"python.linting.pylintArgs": ["--load-plugin","pylint_protobuf"]
The first line really just hides the linting error. Certainly not a permanent solution, but de-clutters the screen.
This answer gave me the second line: VS Code PyLint Error E0602 (undefined variable) with ProtoBuf compiled Python Structure
Maybe someone who understands Python more than me can explain that one more.
Okay, so 2 years down the line, I have ran into this annoying problem. All I can seen here are some really complicated workarounds. Here are easy to follow steps for anyone else who might just run into this later on:
at the bottom of VS Code where you see the Python version listed, just click there
Select Interpreter windows is going to appear
click on the first option that says "Select Interpreter Path" and navigate to the folder path which has your Virtual Environment
That's all you need to do and avoid tampering with those settings in VS Code which might get very complicated if not handled with caution.
My solution
This solution is only for the current project.
In the project root, create folder .vscode
Then create the file .vscode/settings.json
In the file setting.json, add the line (this is for Python 3)
{
"python.pythonPath": "/usr/local/bin/python3",
}
This is the example for Python 2
{
"python.pythonPath": "/usr/local/bin/python",
}
If you don't know where your Python installation is located, just run the command which python or which python3 on the terminal. It will print the Python location.
This example works for dockerized Python - Django.
I was facing the same problem while importing the project-related(non standard) modules.
Detailed explanation of the problem
Directory structure:
Project_dir:
.vscode/settings.json
dir_1
> a
> b
> c
dir_2
> x
> y
> z
What we want:
Project_dir
dir_3
import a
import y
Here "import a" and "import y" fails with following error:
Import "dir_1.a" could not be resolvedPylancereportMissingImports
Import "dir_2.y" could not be resolvedPylancereportMissingImports
What worked for me:
Appending the top directory which contains the modules to be imported.
In above example add the follwoing "Code to append" in ".vscode/settings.json"
Filename:
.vscode/settings.json
Code to append:
"python.analysis.extraPaths": [dir_1, dir_2]
The solution from Shinebayar G worked, but this other one is a little bit more elegant:
Copied from Python unresolved import issue #3840:
Given the following example project structure:
workspaceRootFolder
.vscode
... other folders
codeFolder
What I did to resolve this issue:
Go into the workspace folder (here workspaceRootFolder) and create a .env file
In this empty .env file, add the line PYTHONPATH=codeFolder (replace codeFolder with your folder name)
Add "python.envFile": "${workspaceFolder}/.env" to the settings.json
Restart Visual Studio Code
To me the problem was related with the project that I was working on. It took me a while to figure it out, so I hope this helps:
Original folder structure:
root/
__init__.py # Empty
folder/
__init__.py # Empty
sub_folder_b/
my_code.py
sub_folder_c/
another_code.py
In another_code.py:
from folder.sub_folder_b import my_code.py
This didn't trigger the intellisense in Visual Studio Code, but it did execute OK.
On the other hand, adding "root" on the import path, did make the intellisense work, but raised ModuleNotFoundError when executing:
from root.folder.sub_folder_b import my_code.py
The solution was to remove the _init_.py file inside the "folder" directory, leaving only the _init_.py located at /root.
This works for me:
Open the command palette (Ctrl + Shift + P) and choose "Python: Select Interpreter".
Doing this, you set the Python interpreter in Visual Studio Code.
None of the answers here solved this error for me. Code would run, but I could not jump directly to function definitions. It was only for certain local packages. For one thing, python.jediEnabled is no longer a valid option. I did two things, but I am not sure the first was necessary:
Download Pylance extension, change python.languageServer to "Pylance"
Add "python.analysis.extraPaths": [ "path_to/src_file" ]
Apparently the root and src will be checked for local packages, but others must be added here.
I am using the following setup: (in Apr 2021)
macos big sur
vscode
Anaconda 3 (for environment)
And I faced this error during starting of the Django.
So, I follow these steps and this error is resolved.
Steps are given in these screenshots:
Open settings (workspace)
Follow this screenshot to open Python Path
Now, click Edit in settings.json
Make path like given in this screenshot /opt/anaconda3/bin/python
5. Now, save this settings.json file.
6. Restart the vscode
Also, intellisense might not work for some time hold on wait for some time and then restart again then vscode reads file for new path.
That happens because Visual Studio Code considers your current folder as the main folder, instead of considering the actual main folder.
The quick way to fix is it provide the interpreter path to the main folder.
Press Command + Shift + P (or Ctrl + Shift + P on most other systems).
Type Python interpreter
Select the path where you installed Python in from the options available.
Changing
Python:Language Server
to 'Jedi' worked for me.
It was 'Windows' initially.
For me, it worked, if I setup the paths for python, pylint and autopep8 to the local environment paths.
For your workspace add/change this:
"python.pythonPath": "...\\your_path\\.venv\\Scripts\\python.exe",
"python.linting.pylintPath": "...\\your_path\\.venv\\Scripts\\pylint.exe",
"python.formatting.autopep8Path": "...\\your_path\\.venv\\Scripts\\autopep8.exe",
Save and restart VS Code with workspace.
Done!
I have a different solution: my Visual Studio Code instance had picked up the virtualenv stored in .venv, but it was using the wrong Python binary. It was using .venv/bin/python3.7; using the switcher in the blue status bar.
I changed it to use .venv/bin/python and all of my imports were resolved correctly.
I don't know what Visual Studio Code is doing behind the scenes when I do this, nor do I understand why this was causing my problem, but for me this was a slightly simpler solution than editing my workspace settings.
In case of a Pylint error, install the following
pipenv install pylint-django
Then create a file, .pylintrc, in the root folder and write the following
load-plugins=pylint-django
I have faced this problem in three ways. Although for each of them a solution is available in the answers to this question, I just thought to put it all together.
First I got an "Unresolved Import" while importing some modules and I noticed that my installations were happening in global pip instead of the virtual environment.
This issue was because of the Python interpreter. You need to select the interpreter in Visual Studio Code using Shift + Ctrl + P and then type Select Python Interpreter. Select your venv interpreter here.
The second issue was: The above change did not resolve my issue completely. This time it was because of file settings.json. If you don't have the settings.json file in your project directory, create one and add the following line in that:
{
"python.pythonPath": "apis/bin/python"
}
This will basically tell Visual Studio Code to use the Python interpreter that is in your venv.
The third issue was while importing a custom Python module or file in another program. For this you need to understand the folder structure. As Python in venv is inside bin, you'll need to specify the folder of your module (most of the time the application folder). In my case it was app,
from app.models import setup_db
Verbally, import setup_db from models.py resides in the app folder.
If you are using pipenv then you need to specify the path to your virtual environment.in settings.json file.
For example :
{
"python.pythonPath":
"/Users/username/.local/share/virtualenvs/Your-Virual-Env/bin/python"
}
This can help.
If someone happens to be as moronic as me, the following worked.
Old folder structure:
awesome_code.py
__init__.py
src/
__init__.py
stuff1.py
stuff2.py
New structure:
awesome_code.py
src/
__init__.py
stuff1.py
stuff2.py
How to avoid warning
Please note that this is just skipping the warning not resolving it.
First of all open visual studio code settings in json and add following arguments after "[python]":{}
"python.linting.pylintArgs": ["--rep[![enter image description here][1]][1]orts", "12", "--disable", "I0011"],
"python.linting.flake8Args": ["--ignore=E24,W504", "--verbose"]
"python.linting.pydocstyleArgs": ["--ignore=D400", "--ignore=D4"]
This has helped me to avoid pylint warnings in VSCode.
I have resolved import error by Ctrl + Shift + P.
Type "Preferences settings" and select the option Preferences Open Settings (JSON)
And add the line "python.pythonPath": "/usr/bin/"
So the JSON content should look like:
{
"python.pythonPath": "/usr/bin/"
}
Keep other configuration lines if they are present.
This should import all modules that you have installed using PIP for autocomplete.
I have developed a chrome extension. I made some small updates, and suddely the extension can't be installed through chrome web-store. I get the error
Package is in valid. Details: 'Could not unzip extension'
It appears that there is something wrong with the zip file. As far as i understand when uploading a zip file to chrome web store, it gets encrypted to a crx-file. Could it be a hiccup happening there?
When installing the the extension locally through 'load unpackaged extension' or with dragging a crx file it works fine. So there is nothing wrong with the manifest. I've also checked for invalid filenames. I even created a version with all files stripped away.
I tried the solutions from this SE post as well.
What surprises me is that i can find no support from google on chrome extension. No email or anything i can contact for help.
Any help is appreciated.
I had this same problem just yesterday. What apparently fixed it for me (I tried a lot of things, probably did all the same web searches as you) was zipping the files at top level and not zipping the directory that contains them. That is, the zip listing looks like this:
$ unzip -l extension.zip
Archive: extension.zip
Length Date Time Name
-------- ---- ---- ----
659 03-05-13 14:12 manifest.json
...
And not like this:
$ unzip -l extension.zip
Archive: extension.zip
Length Date Time Name
-------- ---- ---- ----
0 03-05-13 15:41 extension/
641 03-05-13 15:41 extension/manifest.json
...
Even though I swear the latter packaging worked for me earlier.
I had a similar issue today. Solution from rhashimoto didn't work for me.
I develop on Linux, and finally I figured the problem was a file name with a reserved character in it from Windows point of view (":"). I removed the file with the problematic name, re-submitted and it worked all fine.
Incidentally, my zip archive is of the format which is said to cause problem in the above answer, and yet it worked after I fixed the file name problem.
Sometimes this can happen because the extension was created on OS X or Linux, and contains a file whose name is illegal in Windows. See this issue for more details.
The list given in the bug comes from MSDN, which says:
Do not use the following reserved names for the name of a file:
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended.
So for instance, on Windows, you cannot have a file named "aux.css" or "aux.html".
I am running a non-english Windows 7 system, and apparently Oracle SQL Developer (version 3.0.04.34, 64-bit) tries to auto-guess my preferred language based on the OS. Is there any way to change the language to english?
I've tried the tip found at http://misteratmisis.com/infotech/how-change-oracle-sql-developer-interface-japanese-english, namely adding the VM options
AddVMOption -Duser.language=en
AddVMOption -Duser.country=US
to file ide.conf in directory
/ide/bin
within the SQL Developer installation directory, as suggested, but that didn't help.
Solution (edited on 13.09.2012):
I decided to try again the solution proposed by Alex K. and this time it worked, namely adding
AddVMOption -Duser.language=en
to the file sqldeveloper.conf file located in sqldeveloper\bin\ folder. I presume that it did work now but not before, because meanwhile I have changed my UAC (user access control) settings in Windows 7 so that I am administrator by default. What happened before was probably that even though the changes appeared to be there, the configuration file read by the program was another one (shadow copy).
Solution for Mac OS X (added on 26.02.2016):
Edit file at
/Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin/sqldeveloper.conf
and add the line
AddVMOption -Duser.language=en
(Tested with SQL Developer 4.1.3.20)
Try to set user.language and user.country properties in sqldeveloper.conf file located in sqldeveloper\bin folder (%APPDATA%\sqldeveloper\<version>\product.conf for more recent versions) .
Sample for set french language:
IncludeConfFile ../../ide/bin/ide.conf
SetJavaHome D:\jdk1.6.0_25
AddVMOption -Doracle.ide.util.AddinPolicyUtils.OVERRIDE_FLAG=true
AddVMOption -Dsun.java2d.ddoffscreen=false
AddVMOption -Dwindows.shell.font.languages=
AddVMOption -Duser.language=fr
AddVMOption -Duser.country=FR
AddVMOption -XX:MaxPermSize=128M
AddVMOption -Doracle.jdbc.mapDateToTimestamp=false
IncludeConfFile sqldeveloper-nondebug.conf
To switch off language try to remove its support by editing oracle.translated.locales option in ide.boot file (located in ide\bin folder).
For example, if I want to 'break' french language support this option will be:
oracle.translated.locales = de,es,it,ja,ko,pt_BR,zh_CN,zh_TW
The original value was:
oracle.translated.locales = de,fr,es,it,ja,ko,pt_BR,zh_CN,zh_TW
The configuration above (sqldeveloper.conf file) will be wrong after remove french support and the french language does not appear as GUI localization.
You can also set language at runtime
sqldeveloper.exe --AddVMOption=-Duser.language=en
to avoid editing sqldeveloper.conf every time you install new version.
You can also configure directly on the file ..sqldeveloper\ide\bin\ide.conf:
Just add the JVM Option:
AddVMOption -Duser.language=en
The file will be like this:
Or use the menu: Tools->Preferences->Database->NLS and change language and territory.
With SQL Developer 4.x, the language option is to be added to ..\sqldeveloper\bin\sqldeveloper.conf, rather than ..\sqldeveloper\bin\ide.conf:
# ----- MODIFICATION BEGIN -----
AddVMOption -Duser.language=en
# ----- MODIFICATION END -----
Before installation use the Control Panel Region and Language Preferences tool to change everything (Format, Keyboard default input, language for non Unicode programs) to English. Revert to the original selections after the installation.
On MAC High Sierra (10.13.6)
cd /Users/vkrishna/.sqldeveloper/18.2.0
nano product.conf
on the last line add
AddVMOption -Duser.language=en
Save the file and restart.
=======================================
If you are using standalone Oracle Data Modeller
find ~/ -name "datamodeler.conf"
and edit this file
cd /Users/vkrishna//Desktop/OracleDataModeler-18.2.0.179.0756.app/Contents/Resources/datamodeler/datamodeler/bin/
Add somewhere in the last
AddVMOption -Duser.language=en
save and restart, done!
+> In Oracle SQL Developer, you can follow steps by steps as the below image:
+> After opening the file in step 3, you can add this text "AddVMOption -Duser.language=en" to this file and save it.
+> After saving the file, reopen Oracle SQL Developer and check the result.
Problem
Frequently (but not every time) when using CVS to check in files like: .java, .cs, .xml, etc, every line of the file is gets a carriage return.
Example:
File before check-in by a team member:
// Begin file
class Foo
{
public Foo()
{
// Do step 1
// Do step 2
}
}
// End file
File when checked out by a team member:
// Begin file
class Foo
{
public Foo()
{
// Do step 1
// Do step 2
}
}
// End file
Development Environment
NetBeans 6.8 and now 6.9 (the problem occurred when using 6.8 as well).
Visual Studio 2008 and 2010.
Repository: CVS; checkins and checkouts done from Cygwin bash shell.
Operating system: Widows XP Professional.
What I Have Tried
I tried changing the value: build.compiler.emacs=true within NetBeans under Tools->Options, thinking this might be causing some kind of Unix/Windows translation problem when checking in? This made no difference.
Am I missing something about what happens to a file when it gets checked into CVS in a Windows/IDE/Cygwin stack that can cause this problem?
Something is converting DOS line breaks (CR LF) to pairs of Unix line breaks (just LF). I would personally bet on its being CVS. You might want to try using TortoiseCVS instead of Cygwin CVS.
A Windwos-native CVS client will convert MS-DOS line endings in a text file (\r\n) to Unix-style line endings when submitting the file to the server, so that in the repository, the files are maintained in a 'canonical' form with \n representing a line ending. When Windows native client will also convert the line ending when bringing a file down from the server.
However, I believe that the default Cygwin CVS client acts like a Unix client and assumes that no line ending conversion is required. So if you use that client to check in a file with MS-DOS-style endings (\r\n), you'll get this kind of confusion.
It looks like the people who are using the Cygwin client are using tools that care converting the files to MS-DOS style line endings (or something is).
A potential fix is to uninstall the Cygwin CVS client and install the WinCVS client on your Windows/Cygwin boxes so the Windows native client will be used even when a Cygwin shell is active:
http://www.dehora.net/journal/2003/07/a_fix_for_cygwin_and_cvs_linefeeds.html
Another possibility to to configure your Cygwin mounts under a specific mode (but I'm not really familiar enough with Cygwin to know how well this works or if it might introduce otehr problems - it's been a long time since I've tried using Cygwin):
http://www.gigascale.org/softdevel/faq/23.html
Another possibility that I just ran into - if the file was saved in Unicode format but stored in CVS as ASCII/Text, extra line terminators will be added.
I have vi bindings working in my bash shell using set -o vi in my .bash_profile. But I can't seem to get them to work in the mysql command line client. I only get emacs style bindings. How do you do this?
I also put these lines in my .inputrc, but to with no effect:
set editing-mode vi
set keymap vi
Quick google reveals this... don't know if it helps.
Copied here for convenience:
Add the following on OS X 10.5:
$ cat .editrc
bind -v
This will work for OS X 10.4 and
other operating systems:
$ cat .inputrc
set editing-mode vi
These two files worked on my previous workstation (not sure of the MySQL version (my old job)). I keep my dotFiles in git.
.editrc
bind -v
bind \\t rl_complete
.inputrc (several of these may or may-not be needed)
set editing-mode vi
set keymap vi
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
set bell-style none
Posting these because I couldn't post them in my comment above.
This doesn't directly answer your question, but you might want to take a look at the dbext plugin.
This plugin contains functions/mappings/commands to enable Vim to access several databases.
[...]
dbext provides a common interface between your editor and a database. If your company/project moves onto a new database platform, there is no need to learn the new databases tools. While editing your SQL (and without leaving Vim) you can execute database commands, run queries, display results, and view database objects. dbext understands various programming languages, and can parse and prompt the user for [host] variables and execute the resulting statement. See below for more details.
A database client inside Vim!
The voted answer is ok, but if you're encountering problems as it happened to me (I'm currently using Slackware 14.x) then editing /etc/inputrc should be your last hope.
I've tested both .inputrc and .editrc on my home, but on my system only editing /etc/inputrc worked.
Also, this is not answer to your question.
You can also use Vimsql like dbext. Vimsql is more convenient way interacting with mysql than mysql if you love vim key map.