Python Forum
using self-developed modules
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using self-developed modules
#2
Sorry: I'm not yet used to this forum, I managed to file an incomplete question. Here is the completed question:

I use Win10 and Python 3.7.4. I am rather new to Python.

I wrote a python program that contains a number of inline functions and classes followed by a main program. It imports some “standard” modules (sys, decimal, tkinter, …) and also a home-grown module that contains functions and classes that are also used in other modules.

My modules look (simplified) like:

main.py
import sys
from selfwrittenmodule import f1, f2
def if1(x):
….a = f1(x);return(a)
def if2(x):
….a = f2(x);return(a)
b = 2
a = if1(b)
c = if2(b)
print (a, c)

selfwrittenmodule.py
def f1(x):
….some lines of code
def f2(x)
….some lines of code

I stored the “main.py” module in a folder dedicated to “work in progress”. Because “selfwrittenmodule,py” is for use by many other scripts to, it is stored in a folder dedicated to “general use” modules.
In the manuals I found three ways to ensure that the python interpreter finds modules in other folders:
1) Add a “PYTHONPATH” variable to the system variables and have it point to the “general use” folder.
2) Add the “general use” folder to the “%PATH%” system variable.
3) Move the “general use” folder, with the “selfwrittenmodule.py” in it, into C:\Users\actname\AppData\Local\Programs\Python\Python37-32\Lib

I tried all three methods, no joy: when I press “F5” in idlex, I receive an error message that the “selfwrittenmodule.py” is not found.

Then I moved “selfwrittenmodule.py” to the folder that contains “main.py” and press f5 in idlex. Now the python interpreter finds “selfwrittenmodule.py” and “main” is “compiled” and executed fine.

Question: how can I store “selfwrittenmodule.py” in a folder different from my “work in progress” folder and be able to import it correctly in another module by the python interpreter?
Reply


Messages In This Thread
using self-developed modules - by wlp - Aug-28-2019, 03:04 PM
RE: using self-developed modules - by wlp - Aug-28-2019, 04:05 PM
RE: using self-developed modules - by snippsat - Aug-28-2019, 05:41 PM
RE: using self-developed modules - by wlp - Aug-29-2019, 10:36 AM
RE: using self-developed modules - by perfringo - Aug-29-2019, 11:22 AM
RE: using self-developed modules - by snippsat - Aug-29-2019, 03:29 PM
RE: using self-developed modules - by wlp - Aug-29-2019, 04:18 PM
RE: using self-developed modules - by snippsat - Aug-29-2019, 05:20 PM
RE: using self-developed modules - by wlp - Aug-30-2019, 02:18 PM
RE: using self-developed modules - by snippsat - Aug-30-2019, 03:17 PM
RE: using self-developed modules - by wlp - Aug-30-2019, 04:16 PM
RE: using self-developed modules - by snippsat - Aug-30-2019, 07:10 PM
RE: using self-developed modules - by wlp - Aug-31-2019, 01:45 PM
RE: using self-developed modules - by snippsat - Aug-31-2019, 05:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Developed App in VS2019 - Help with pyinstaller fioranosnake 0 1,630 Nov-11-2019, 09:12 PM
Last Post: fioranosnake
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 8,521 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