Python Forum

Full Version: Installing py Files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I have a bunch of .py files sitting in my command line directory path and I wish to install them to Python3. I have tried 'sudo apt install filename.py' and sudo apt-get install python-filename ect but they don't recognize the files. Any solutions please?

Regards
dave
You could do the following
  1. Create a directory for these Python files, for example /home/myname/pymods
  2. Find the per user site-packages directory. For this, start python and run
    >>> import site
    >>> site.getusersitepackages()
    On the computer where I'm writing this, it prints '/home/eric/.local/lib/python3.8/site-packages'. This is the path to the directory
  3. In this directory, create a file named usercustomize.py (if it does not already exist). In this file add code
    # usercustomize.py
    import site
    site.addsitedir('/home/myname/pymods')
You can now import these python modules.