I keep getting this error in VS Code:
Traceback (most recent call last):
File "c:\Users\User Name\Documents\Productivity\Coding\Python\Udemy\Projects from course\MilestoneP2\app.py", line 1, in <module>
import MilestoneP2.utils.Operations_db as Db
ModuleNotFoundError: No module named 'MilestoneP2'
I have recently shifted from Pycharm to VS Code and I am trying to open some of those projects from pycharm in VS Code but there is the above error haunting me.
PS: I have my Python Interpreter in a different directory and not in the workspace folder. It's in D:\Python\venv Drive
Here is my code:
import MilestoneP2.utils.Operations_db as Db
Here is the file hierarchy.
Anyone Help?
Thank you
If you run the script within VSCode there is a Python version button on bottom-left.
When you click on it you can specify your Python or virtual environment path. It will also try to find them automatically from directories. Then you can run your scripts with the spesified environments.
Related
I'm using Pymakr on VScode to program a Pycom L01, which is connected to several sensors.
i'm trying to use smbus2 library, but i can't import it.
I created a python virtual enviroment and installed it using 'pip install smbus2', but when i try to upload the sketch, the output is:
Traceback (most recent call last):
File "main.py", line 4, in <module>
File "/flash/lib/bmp280.py", line 3, in <module>
ImportError: no module named 'smbus2'
Pycom MicroPython 1.18.2.r1 [v1.8.6-849-e0fb68e] on 2018-12-08; LoPy with ESP32
Type "help()" for more information.
Someone who can help me?
May be You have not installed smbus2 module. Please install it and import it in your program.
Solved, that was a noob mistake.
The project files were outside the virtual enviroment directory.
oof.
I have my own project with virtual environment. When I am trying to debug code everything executes flawlessly and I get the expected output, but when I am trying to run it with run code option from Code Runner extension I receive the error:
[Running] python -u "c:\Users\slikm\Pulpit\ytapi\yt_api.py" Traceback (most recent call last): File "c:\Users\slikm\Pulpit\ytapi\yt_api.py", line 2, in <module> from googleapiclient.discovery import build ModuleNotFoundError: No module named 'googleapiclient'
I have the library which the module is taken from installed on my venv. I read that the problem might be with the interpreter the extension uses, but I don't really know how to figure it out.
I'm setting up a Flask application on Digitalocean and have Python 3.7 installed and the latest version of Flask. When running the app inside a virtualenv and trying to run the application using python3.7 application.py I get the following error message:
Traceback (most recent call last):
File "application.py", line 11, in <module>
from config import *
ModuleNotFoundError: No module named 'config'
What puzzles me is that config.py is located in the same folder as application.py, and not in a subfolder. I have duplicated the setup on my local machine, also running Python 3.7 and inside a virtualenv, and the importing (and the app) works flawlessly.
I've tried importing "config.py" instead of just "config" but didn't make a difference. I also tried specifying exactly what it should import (instead of using '*') but that didn't make a difference either.
Your thoughts on why it can't find config?
What seems to have been the solution to my problem above was to run the Python shell and add the path to the directory in which config.py is located (even though it's in the same folder as application.py...) by using the following command:
sys.path.append("/path/to/config/")
This code worked on Friday without problems and still running on a colleagues laptop, but I cannot run it anymore.
As you can see in the screenshot, my editor doesnt find some moduls anymore and the pylint Error "E0401: Unable to import" occurs.
The missing file exists in the folder Settings, as you can see in the Explorer on the left side.
Today I deactivated/activated pylint, reinstalled vs code and python, added the init.py to Settings folder, tried the same code in eclipse, modified the Path enviroment variable and created the PYTHONPATH enviroment variable. All this with no success:/
I am greatful for each hint, which provide me to solve this problem.
The error output as text:
Windows PowerShell
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
PS C:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev> & C:/Python27/python.exe c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\__TC__Template.py
Traceback (most recent call last):
File "c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\__TC__Template.py", line 36, in <module>
from Lib.IHR_EthApi import EthApi as ETH
File "c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\Lib\IHR_EthApi.py", line 6, in <module>
from IHR_GeneralApi import GeneralApi as SYS
File "c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\Lib\IHR_GeneralApi.py", line 4, in <module>
import IHR_TestSuiteConfig.py
ImportError: No module named IHR_TestSuiteConfig.py
PS C:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev>
In your code you have the line:
import IHR_TestSuiteConfig.py
That won't work because you don't specify modules to import by file name but by module name, e.g.:
import IHR_TestSuiteConfig
But looking at your screenshot you have a bigger issue of the code being kept in a Settings directory at the same level as your Lib directory containing the code you are importing into.
You need to either anchor all of your code up a level so you can do:
from ..Settings import IHR_TestSuiteConfig
Or you need to manipulate your PYTHONPATH environment variable to put Settings directly on to sys.path (in VS Code you can create a .env file to do this, but it won't' affect running Python from the terminal, only when VS Code runs e.g. Pylint).
I have installed python 2.7.12 with PATH access and correctly installed twilio. However, when I try to execute a code I get this error message:
Traceback (most recent call last):
File "C:\Python27\textmessage.py", line 1, in <module>
from twilio.rest import TwilioRestClient
ImportError: No module named twilio.rest
Also, I want to know where we have to install Twilio, as I installed the Twilio library and placed it inside the Scripts folder.
You should not put modules into the Scripts folder.
To install twillio, see the documentation.
Check the path. I had the same problem when I put the file send_text.py in the folder called C:\Python27\Projects. I then copy the file and placed in in the folder C:\Python27 where the libs folder is right under it. The module ran. This was a test on my system.