0

I am using python and I created a simple way to write HTML and output the file. I developed this module on 2 computers in which on the main one I could use the following according to the directory tree:

Pypertext:
   html.py
   widget.py
   htmlHeader.py
   htmlTitle.py
   htmlButton.py

This is the folder of the module that can be imported using:

from pyperclip.htmlHeader import Header

although in htmlHeader.py I have the following import:

from widget import baseWidget

This runs fine on my computer but when I go to the secondary computer I get an error and I fixed by:

from .widget import baseWidget

On my main computer I get an error for the attempted relative import and I feel that in the module script it should not have to be a lot of try except statements to make it work. I use python 3.10

  • 3
    Do you run them any differently between the two computers (e.g. run one from an IDE and one from the command line)? You could also put a print statement at the top to check the current working directory `print(os.getcwd())` and see if that gives you a clue – Sobigen Jan 06 '23 at 00:25
  • 1
    Does Pypertext have an `__init__.py` file ? Strictly speaking relative imports are only intended inside a package, and it is only the existance of `__init__.py` file that defines a package. Are your two computers different O/S or O/S versions - it could be a difference in O/S which explains why one relative import works. You are correct that the the same code should work on every macine (unless the code is O/S dependent). – Tony Suffolk 66 Jan 06 '23 at 09:31
  • they both run in pycharm, they are both windows 10 – user19926715 Jan 06 '23 at 15:28
  • there are no OS dependent modules in them and there is `__init__.py` – user19926715 Jan 06 '23 at 15:28
  • What is the run configuration in pycharm? – Mr_and_Mrs_D Jan 06 '23 at 23:28

0 Answers0