2

I am using python/selenium in visual studio code. I am trying to import my another python class driverScript which resides in executionEngine module and in the file DriverScript. I have imported as below:

import driverScript from executionEngine.DriverScript 

It is producing error:

Traceback (most recent call last):
  File "c:/Selenium/Selenium-Python Framework/RK_Practice/Tests/mainTest.py", line 5, in <module>
  from executionEngine.DriverScript import driverScript
ModuleNotFoundError: No module named 'executionEngine'

How can I import correctly? Your help is very much appreciated.

3 Answers 3

2

If the script you are wishing to import is not in the current directory, you may want to take this approach:

import sys

sys.path.insert(1, '/path/to/script/folder')

import driverScript from executionEngine.DriverScript
Sign up to request clarification or add additional context in comments.

Comments

0

Depends on where executionEngine is supposed to come from. If it's from a package installable via a package manager such as pip or Anaconda, looks like it's not properly installed. If you installed it yourself, you probably need to add the directory containing executionEngine to your PYTHONPATH, so the Python interpreter can find it. This can be done in the VSCode environment files. See the PYTHONPATH section in https://code.visualstudio.com/docs/python/environments

1 Comment

executeEngine is a folder in which the file DriverScript.py existed. And I am trying to import this from another file mainTest.py which resides in Tests folder.
0

If your python file is on the same level in dir, then you can import just by calling:

import filename

If your python file is inside another folder, then you need to create a blank __init__.py file that will help python to understand it's a package. Then you can import that as follows:

from folderName import filename

5 Comments

Python file is inside another folder. Where should I create blank ini.py file? Is it in the folder where called python file existed (or) in the folder from where I am calling?
folder where called python file existed
create ini.py twoo underscore before and after the ini
Created as suggested. No use. Still issue existed :(
I have attempted to select python init generator as mentioned in link below: marketplace.visualstudio.com/… Steps are given as below: 1. Open your workspace or directory. 2. Press Ctrl(Cmd) + Shift + P 3. Just select Python init Generator: Generate init.py But, Python Init Generator is not available on search in Command Palette. Do I need to configure or install something to see this in Command Palette.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.