我在相同的文件夹/包中有这些python脚本(文件夹或包可以被称为相同吗?因为所有内容都在同一个文件夹中,所以我将其称为包?对吗?):

我的第一个python脚本将其命名为“ scriptA.py”:

import pandas as pd
import json
import requests
import scriptB
import scriptC
import enum
import sys
import os

"""
In this "scriptA", I will call both "scriptB" and "scriptC" to further do more processes.
"""


然后我有脚本“ scriptB.py”:

import pandas #since "scriptA" will already imported it should I not include it here? how can I do so? The rest will have the same issue too.
import glob
import os


然后我有脚本“ scriptC.py”:

import pandas as pd
import os
from sklearn.model_selection import train_test_split


我的问题:

我如何构建setup.py,以便用户可以只使用pip install e。它将在所有3个脚本中安装所有软件包?你有例子还是可以写一个给我看?

我的个人信息;抱歉,我的问题里面有多个问题。

最佳答案

我不确定执行此操作的“正确”方法,但是以下代码肯定可以工作。

import pip#导入默认包

def install(package):
    if hasattr(pip, 'main'): #later versions of pip do not have this attribute so just checking
        pip.main(['install', package]) #install the package name as passed in the parameter
    else: #if pip upto date then simply install the package
        pip._internal.main(['install', package]) #if

# Example
if __name__ == '__main__': #you want to make sure that this doesn't run every time this file is imported somehwere and runs only when you run the particular script
    install('pandas') # you can use an entire list of all your required packages

关于python - 根据我的多个python脚本创建setup.py,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58406488/

10-12 16:47
查看更多