Reputation: 619
Im having trouble importing a class on a python module.
Here are my directory structure:
TestMap
+lib
+vendors
+testing
- _init.py
- products.py
- _init_py.
- notifications.py
- scraper.py
- utils.py
-main.py
And I'm starting on scraper.py
and trying to get functions on products.py which is vendors -> testing -> products.py
from .vendors.testing.products import TestProducts
and what I am trying to do is:
ImportError: cannot import name 'TestProducts' from 'lib.vendors.testing.products' (C:\Users\Annoynmous\Desktop\TestMap\lib\vendors\testing\products.py)
and inside the products.py the class name is:
class TestProducts():
and I cant get a grip what I am actually doing wrong?
Upvotes: 0
Views: 927
Reputation: 1700
Try this in scraper.py
from vendors.testing.products import TestProducts
Or
import vendors.testing.products as product
class scraper:
def __init__(self):
self.product = product.TestProducts()
Use self.product
to access any function of TestProducts inside the class scraper.
Upvotes: 1
Reputation: 1375
Use pythonpath
to set the source directory in your project:
export PATH=$PATH:/home/user/somepath/TestMap
and import the modules from that source path
from lib.vendors.testing.products import TestProducts
Or use __init__.py
file to define your internal module directory and import the module with direct module name.
Upvotes: 1