How do import kivy in VS Code? - python

I've installed Kivy.....a lot of times.
I'm in VS Code and it shows in Libraries but I can't seem to figure out how to import.
Getting kivy module does not exist error.
Can run a .py file with just import kivy in the terminal with success.
Cannot run kivy built-in example from terminal. ErrNo2

You're opening python environment as current project. It's not recommended to do so, and we usually open a folder and select the python environment as interpreter.
Turn back to your question, make sure you've selected the opened environment as interpreter. Open Command Palette, click Python: Select intepreter then enter interpreter path. It will pop up a folder explorer, choose your current opened Scripts\python.exe, then you can import kivy successfully:
More information please view Python Tutorial and Python Environments.

Related

Kivy module not found in vscode (Mac)

I have installed Kivy and when I used the IDLE app that came with Python I can import it and it runs perfectly. However, when I try to import it in vscode I get the error:
ModuleNotFoundError: No module named 'kivy'. I can not find out what to do and the environment from the kivy dmg does not open so I feel lost. Can someone help me?
Two solutions
Check the python interpreter being used
When any .py file is open in the editor and is currently being used, near the bottom left, it says Python <version> <32/64>-bit. Tap it and select the directory that contains the python interpreter version that has kivy installed.
Check the following image for any help
The platform I was using was a chromebook, but the location of changing the editor is the same
Manually install within VScode
Run pip install kivy to ensure that vscode uses it

VSCode not selecting the correct python interpreter

I have a script that I need to run using a very specific python interpreter in my hard drive.
I am using vscode as the IDE and trying to select the python interpreter using the command palette.
However, since the concerned interpreter is not present, I manually search it.
However, even after that, it doesn't work as typing python in the terminal then opens the windows store for installing a python IDE. I also tried adding the interpreter's path to the environment variables but the problem still persists.
How do I solve this issue.
Thank You for the help.
The Python version you selected on VS Code only effects the editor. Right click to any file on the sidebar and select Open in Integrated Terminal. If your selected Python version is created with virtualenv it will activated and your python command works.
If not worked and you want a global Python version, you need to add Python path to your system variables to work python command. Check this:
https://geek-university.com/python/add-python-to-the-windows-path/
Btw I don't think your python.exe in FreeCad/bin directory is proper Python version
At the bottom left you can select the Python interpreter.
Here it shows you on -how to do that: Python Interpreter
Reason:
Your system environment path contains this: %USERPROFILE%\AppData\Local\Microsoft\WindowsApps.
Solution:
Open Window Search(Win) to find Manage app execution aliases. To turn off App Installer of python3 like this:
You can refer to this answer for more information.

ModuleNotFoundError: No module named 'requests' (VS Code with Anaconda interpreter)

Hi I'm really new on the programming. I am using VS Code with Anaconda interpreter:
Here
I am using Windows 10
I want to import "requests" module on my VS Code. I opened cmd and wrote "pip3 install requests" but it told me "Requirment already satisfied:" etc... Then I tried to download with Anaconda. I opened my cmd and wrote "conda install requests" and I downloaded.
Then I wrote this code to try module: Here
But I received an error in VS Code like that: Here
What can I do to solve this problem? Thank you so much for your answers. (By the way, sorry for my bad English :D I hope I explained my problem.)
Click in bottom left cornet in VS code on (Python <Version>) and then choose the python version that in your system.
I have just found the answer. In VS Code, I open powershell and write "py (filename).py". But just now, I tried to click top-right button which name is "Run Python File in Terminal" (green button). Then code executed successfully. I didn't take an error.
Check the following prospects in vscode with python extension:
When selecting interpreter, press ctrl+shift+' to open a new integrated terminal. If you selected base:conda environment, the terminal should be like this:
Then use pip list to show modules you've installed, if module requests not there, type commands pip install requestsin the terminal;
click then create a launch.json file, select Python File. This creates and opens a launch.json. You can close it or add configurations you want. More guidance about debug configurations you can reference: Python debug configurations in Visual Studio Code. Press F5 to run your code.
Just make sure the module installation is in the same environment as interpreter you've selected.

Can't run kivy file on Komodo

I'm trying to run a Kivy python file on Komodo IDE (for Mac) but its giving me this error
import kivy
ImportError: No module named kivy although if I drag-drop the file on the Kivy app its running normally,
any ideas ?, thanks
Try going to Edit > Preferences > Languages > Python > Additional Python Import Directories, and adding the directory where Kivy is installed. I am not sure on a Mac where this would be. To find out, in a python interpreter (or elsewhere - wherever you are able to successfully import kivy) do:
>>> import kivy
>>> kivy.__file__
and add the directory one up from kivy/ in that path through the Komodo settings as described above.
This only works for Komodo code intelligence. Run time is still limited to PYTHONPATH. To run a script that's using Kivy, even in your command line, the kivy source has to be on your PYTHONPATH.
You can add items to your PYTHONPATH in Komodo using Edit > Preferences > Environment then create a New environmental variable to append the kivy installation location to your $PYTHONPATH, ie $PYTHONPATH:install/location/kivy.
If you don't mind having it in your system though, I'd just do what #tuan333 suggest above, install it using pip, then make sure you're using THAT Python interpreter in Komodo.

"ImportError: No module named cv2" when running Django project from PyCharm IDE

I'm running a Django project from PyCharm with the configuration set up to use the Python interpreter from a virtualenv which has a dependency on opencv. The site works fine locally when I run django-admin.py runserver, however I keep getting an "ImportError: No module named cv2" error when I try to run the project directly from the PyCharm IDE.
Has anyone else had this issue with PyCharm and opencv?
In the end I ended up having to set an environment variable directly in the Pycharm Edit Configurations -> Run/Debug Configurations -> Environment Variables panel. I added the following option after you hit the edit button: set name to PYTHONPATH and value to /usr/local/lib/python2.7/site-packages:$PYTHONPATH which should display in the input box after editing as PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH. Also, I made sure to log out and log back in of osx which also worked for a couple other path related issues.
I'm not quite sure if this works for you guys but it works for me. In my case, it seems to me that I installed OpenCV to work with the default Python arriving with OS X. I remember I tried to install Python 2.7.5 and Python 3 in my Mac as well, I see them when I chose my Python interpreter for Pycharm. And all of them didn't let me import module cv2. So I change to the default Python2.7.2 (/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python). Then, in File/DefaultSettings/Project Interpreter/Python Interpreter, click on the Python interpreter that's been added (Python 2.7.2), click on Paths and locate to "/usr/local/bin/python2.7/site-packages"and add it. Click the blue refresh button, apply and ok. Then it works, both with import and autocompletion.
Regards,

Categories