Unable to Import & Import could not be resolved - python

i started programming today and i'm testing different code segments on Visual Studio Code. However, when i tried importing a "numpy", 2 errors occured. I then proceeded to check other stack-overflow posts regarding this and I tried switching the Python Interpreter, however nothing changed. I also attempted doing other suggestions, however I don't understand how to do some of the suggestions (its my first time programming etc.)
enter image description here
Below is a zoomed up picture of it
enter image description here
I was wondering if I could get some help?

Run
pip show numpy
in integrated terminal, check if its location is <your selected interpreter>\lib\site-packages.
If is, reload window then the error should go away.
If not, please open an integrated Terminal and reinstall the module to current selected python environment.

Try opening the project folder in VsCode instead of opening the file by itself. If that doesn't work, run the file through CMD, if running it through CMD doesn't work, you might not have the numpy library. You can do that by going to CMD and write the following command:
pip install numpy

Related

VS Code Python youtube_dl will not import

I have tried every tutorial online and every troubleshooting I have installed youtube_dl in everyway possible all the pip commands and using the exe NOTHING will work I have tried adding it to PATH still nothing at this rate im thinking its an impossible error
Im using visual studio code
See the selected interpreter shown in bottom left corner, run pip show youtube_dl in terminal, check if its location is /selected interpreter/lib/site-packages.
If it is, reload window should solve your question.
If not, please open an integrated Terminal and reinstall the module to current selected python environment.

Can't import Python modules after transferring to VSCode from PyCharm

My basic issue is that I get an error whenever I try to import a Python module in VSCode, which doesn't happen when using PyCharm.
From what I've read so far the problem seems to be with the python path, or the interpreter.
My issue is, that I don't really understand what the issue is, meaning I quickly feel lost when trying to apply some of the other solutions I have found, because I don't know what to look for.
Can someone clarify what is going wrong and how to fix it?
Edit: I probably forgot to add a crucial detail. I was facing this issue when running my python files using the code runner.
This is what I needed to add to my settings.json in order to get everything working completely:
"code-runner.executorMap": {
"python": "$enterPythonPathhere"
}
In VS Code press Ctrl+Shift+P
Type select interpreter in the search box
Python: Select Interpreter
This will show a couple of environment paths. Click on the environment you were using in pycharm.
If your pycharm environment does show on the list you should enter the environment path instead. That should work.
For installing and using python modules in VS Code, please refer to the following:
As people mentioned, select the desired python environment in the lower left corner of VS Code.
Please use the shortcut key Ctrl+Shift+` to open a new VS Code terminal, and then check whether it has entered the selected python environment.("python --version" or "pip --version")
Install the module.
Check the installation of the module.(pip show module_name)
Reference: Python environments in VS Code.

Importing python modules in vscode vs interactive shell

I am just learning python. I am trying to import modules in vscode, installing them using pip. When I try to import the module it says (Pic 1) I have already satisfied the requirements but then (Pic 2/3) it says module is not found when I go to run the program in the Jupyter interactive shell. (Pic 4) However when I run the same code in the python interactive shell it works fine. This seems to be happening for all modules not just the one in this example (pyperclip). It seems like vscode/Jupyter may be looking in a different place than the python interactive shell is. However I am stuck at this point and not sure what else to try.
Thank you for you time and any help you may be able to provide.
(Pic1) Installing module with pip
(Pic 2) Code I am trying to run
(Pic 3) Output from Jupyter shell
(Pic 4) Same code in python interactive shell
I think you need to install you package using anaconda prompt, because sometimes its happen when you are using different platforms. So try pip install pyperclip in Anaconda prompt, hope this will solve your problem, if not then watch this video completely which will give you an idea how these import error occurs and what are the solutions.

Vscode can't use the function "go to definition" and can not open file in PROBLEMS

I'm using VScode for my python project on macOS, but I cannot use the function of go to definition and can not open file in PROBLEMS.
For example:
when I control-click (macOS) and select go to definition, it raise a warning like this:
Unable to open 'spider.py': A system error occurred (ENOTDIR: not a directory, stat '/Users/gassy/Documents/python_spider/toutiao/spider.py/Users/gassy/Documents/python_spider/toutiao/spider.py').
Also, when I click an entry listed in PROBLEMS, it also give the same error:
It seems like a problem creating the path to the file as the path is repeated in the error message like path/to/file.py/path/to/file.py
Go to Definition works for global variables.
System: macOS Mojave
Version: VScode 1.30.2
You can install the extension pydev in vscode.
The extension website is https://marketplace.visualstudio.com/items?itemName=fabioz.vscode-pydev
If you using Python3, Please visit the official website
http://www.pydev.org/vscode/
Finally ,I find the reason!
I thought this bug may be produced by an extension, so I reinstalled VScode for many times followed the method of this website
uninstall-remove-vscode-mac
and tried to find the reason.
When I install Visual Studio IntelliCode, it ask me to install Microsoft Python Language Server. After that, this bug happened.
Hope this solution will help you.
The same problem happened to me.
And it turn out to be the Chinese path that caused this problem.
Copy the folder to a path that contains no Chinese character, and things work well for me

Problems with Pygame on MAC OS X

I am having trouble setting up Pygame on my MAC. Here are my specifications: OS X El Capitan 10.11.4. Whenever I run a file with import pygame I get the following error message in terminal:
ImportError: No module named 'pygame'
If I try to install pygame from bitbucket that the directions, which I am following told me to do, I get the following message:
-bash: /usr/local/bin/pip3: /usr/local/opt/python3/bin/python3.5: bad interpreter: No such file or directory
Again, that message appears when I run the following command, in terminal:
enter code here pip3 install --user hg+http://bitbucket.org/pygame/pygame
I have tried Youtube videos and stack overflow but nothing seems to help me. I believe, but I am not sure, that I am still pointing to python 2.7 and I have no idea how to fix that. I believe I am using python 3.4. I find problems similar to mine but not sure exactly what to do. Any help would be great! Thank you!
Note, I'm not currently on a mac so I'm doing kind of from memory and what I assume should work so some of this might be different for you.
open terminal and type:
which python3
Copy the value of what the which command returns.
Open up your ~/.bash_profile using a text editor, I think you can just type (but not sure)
edit ~/.bash_profile
and you can add these two lines into your bash profile:
PATH="[Replace me with what the which command returned]:${PATH}"
export PATH
save and then in your terminal window you can type:
source ~/.bash_profile
echo $PATH
python --version
to verify that it's picked up your changes.
A few caveats I can think of are compatibility between things using python 2.x and 3.x, and this could break existing programs, so if you need to change back for whatever reason just delete the lines you added into your bash profile.
I found that the information at this site worked: https://bitbucket.org/pygame/pygame/issues/82/homebrew-on-leopard-fails-to-install

Categories

Resources