Skip to content Skip to sidebar Skip to footer

Import A Module Or Add A Path One Time Forever In Python

I want to work with smartcard readers. So I must import some modules such as core from pycard library. Q1: How I can do it automatically! Now each time I open PythonGUI I must impo

Solution 1:

Part 1:

From the Python Docs:

Upon startup with the -s option, IDLE will execute the file referenced by the environment variables IDLESTARTUP or PYTHONSTARTUP. IDLE first checks for IDLESTARTUP; if IDLESTARTUP is present the file referenced is run.

IDLESTARTUP is an environment variable that tells the IDLE the location of a python script to execute on startup, as long as the -s option is given when you start the IDLE. Thus you need to edit the script pointed to by IDLESTARTUP or PYTHONSTARTUP, add the import ... statement, and use the -s flag to start the IDLE.

Part 2:

To add to the sys.path permanently, you can edit the same file we edited above (the file referred to by IDLESTARTUP or PYTHONSTARTUP, and do a

import sys
sys.path.append("...")

Note on Environment Variables:

To figure out if you have a IDLESTARTUP variable or PYTHONSTARTUP variable defined in Windows, you should be able to go to Control Panel > System and Security > System > advanced > Environment Variables.*

*(I'm not much of a Windows user, so you might need to seek out how to change environment variables in Windows on other questions or Google).

Post a Comment for "Import A Module Or Add A Path One Time Forever In Python"