Python Forum
confusion on importing modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
confusion on importing modules
#5
Can also advice to make a virtual environment(build into Python) then search path to folder will work.
Example setup.
myproject/
│
├── Browser/                 
│   ├── __init__.py                # Makes Browser a Python package
│   │
│   ├── src/                      
│   │   ├── __init__.py           
│   │   └── URL.py               
│   │
│   └── test/                      
│       ├── __init__.py          
│       └── test_URL.py           
│
└── other_project_files/           # Other project files (if any)
Start like this:
# Make
G:\env
λ python -m venv myproject

G:\env
λ cd myproject\

# In Linux source bin/activate
G:\env\myproject
λ G:\env\myproject\Scripts\activate

# Now working see (myproject) 
G:\env\myproject
(myproject) λ 

# Eg make folder folders/files from command line or use OS file explorer 
G:\env\myproject
(myproject) λ mkdir Browser

G:\env\myproject\Browser
(myproject) λ touch __init__.py
....
Test run.
G:\env\myproject\Browser\test                                                           
(myproject) λ rich test_URL.py                                                                                       
# Advice use pytest instead 
import unittest                                                                         
import Browser.src.URL                                                                  
                                                                                        
class test_URL(unittest.TestCase):                                                      
    def test_init(self):                                                                
        test_URL = "https://python-forum.io"                                            
        self.assertEqual(test_URL, Browser.src.URL.web_url())                           
                                                                                        
if __name__ == '__main__':                                                              
    unittest.main()                                                                     
                                                                                        
G:\env\myproject\Browser\test                                                           
(myproject) λ python test_URL.py                                                        
.                                                                                       
----------------------------------------------------------------------                  
Ran 1 test in 0.000s                                                                    
                                                                                        
OK                                                                                      
                                                                                        
G:\env\myproject\Browser\test                                                           
(myproject) λ
Reply


Messages In This Thread
confusion on importing modules - by carter187 - Mar-03-2024, 12:27 PM
RE: confusion on importing modules - by Gribouillis - Mar-03-2024, 01:44 PM
RE: confusion on importing modules - by carter187 - Mar-03-2024, 04:05 PM
RE: confusion on importing modules - by Gribouillis - Mar-03-2024, 05:13 PM
RE: confusion on importing modules - by snippsat - Mar-03-2024, 08:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Importing modules from different folders Tomli 3 1,503 Jun-26-2022, 10:44 AM
Last Post: snippsat
  Importing modules issue mp3909 9 3,606 Jun-24-2020, 10:07 PM
Last Post: snippsat
  Importing Custom Modules in Python 3 Flexico 1 2,623 Aug-24-2019, 08:11 PM
Last Post: snippsat
  Trouble importing modules on a new python version snackman_barry 2 2,602 Jul-12-2019, 11:15 AM
Last Post: snackman_barry
  importing modules PiaNa 1 1,996 Jun-24-2019, 12:50 PM
Last Post: ichabod801
  Importing all modules and using it rohitnirantar 2 2,579 Aug-28-2018, 08:15 PM
Last Post: snippsat
  Importing modules SBachar 2 3,090 Apr-06-2018, 09:08 PM
Last Post: snippsat
  Importing modules Pistolpete 2 2,736 Nov-29-2017, 05:24 PM
Last Post: nilamo
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 8,518 May-25-2017, 08:15 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020