0

As I don't have the permission to install Python packages, and I need to use an external library, I am trying to copy all the source files from an installed version of that package in a folder and then use those files instead of installing the package. Also I don't want to use virtual environment for this task.

So this is what I have done:

  1. I have installed the library, lets call it external_lib on a machine that I have permission to install it.

  2. I have copied all the files of that library to a folder; lets call it ext_lib_folder, that is at the same level of my Python code (that is going to use that library).

  3. I have added this to my python code:

    import sys, os
    
    file_path = 'ext_lib_folder/'
    
    sys.path.append(os.path.dirname(file_path))
    
    import external_lib 
    

But when I try to run the code I get error as:

ModuleNotFoundError: No module named 'ext_lib._abcfunpy'; 'ext_lib' is not a package

what is the reason for the error? How can I do what I want to do correctly?

azro
  • 53,056
  • 7
  • 34
  • 70
TJ1
  • 7,578
  • 19
  • 76
  • 119
  • https://stackoverflow.com/questions/20394613/add-a-folder-to-the-python-library-path-once-for-all-windows and https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path?rq=1 might help – Larry the Llama Dec 01 '21 at 19:39
  • And you can't use "pip install --user" to install as a non-admin? – Alan Dec 01 '21 at 19:43
  • @Alan, I want to know if it is possible without your suggestion. Although I also tried `pip install --user ext_lib` and give me this error `no such option --user` – TJ1 Dec 01 '21 at 19:55

1 Answers1

0

Below is an example of how to do this with selenium. I saved the library to a folder "C:/Py" along with geckodriver.exe

import sys, os
file_path = 'C:\\Py\\selenium'
sys.path.append(os.path.dirname(file_path))
from selenium import webdriver
from selenium.webdriver.firefox.service import Service

service = Service('C:\\Py\\geckodriver.exe')
driver = webdriver.Firefox(service=service)
driver.get("https://www.google.com")
Jortega
  • 3,616
  • 1
  • 18
  • 21