Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

python - Is it possible to install scikit-learn on machine without internet and a custom path libraray?

Test 1

I installed scikit-learn 0.23.2 on my virtual environement on my local machine (Windows) and uploaded to the content of the site-pakages to my second machine that does not have access to internet.
Since I don't have admin write permission on the default Lib/site-packages, I put the packages necessary for every project on project specific folder and then point to it on my python code.

Until now, I've managed to use python packages using the hack :

import sys
sys.path.insert(0, "path_to_my_site-packages-folder")
import foo

When I did the same trick with scikit-learn packages, and tried to import it in my code, Python throws an error like this

enter image description here

Test 2

The second Test is the method suggested by @Sahil_Angra. In this test, I've downloaded the necessary packages (scikit-learn in this example) on my local machine and then uploaded the wheel files to the other machine. Then I installed the packages using the wheel files.

Step 1: Download wheels on local machine and store them in a folder

pip download scikit-learn==0.23.* -d 'path_to_folder_that_will_contain_wheel_files'  

Step 2: Transfer the compressed folder to the machine without internet

tar cvfz dependencies.tar.gz 'path_to_folder_that_contain_downloaded_wheel_files' 

Step 3: Install the package on the machine without internet

tar zxvfv dependencies.tar.gz  
cd dependencies 
pip install scikit-learn==0.23.* -f ./ --no-index --path 'path_of_custom_library_folder'

The installation went fine and no error message was shown. However I got the same error when I import something from sklearn in my Python code

Question

So I was wondering if this is due to the fact that Scikit-learn uses some Cython code and if there is a work around to solve the problem?

System information on local machine

System: Windows
Release: 10
Version: 10.0.17134
Machine: AMD64
Python : 3.7.0
pip : 19.1.1
Compiler : MSC v.1912 64 bit (AMD64)

System information on machine without internet

System: Windows
Release: 2008ServerR2 Version: 6.1.7601
Machine: AMD64
Python : 3.7.1
pip : 19.1.1
Compiler : MSC V.1912 64 bit (AMD64)

Cheers,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Copying of contents of site-packages to the second machine bounds to give an error if all the relevant folders and files of the package are not copied.

For your issue, I would suggest downloading the .whl file (available on Pypi) for your package onto your system one. And sending the file over to system two and installing it using

pip install "path/filename.whl"

This would build the module from scratch and install it without any errors


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...