gpt4 book ai didi

python - 基于我的多个 python 脚本创建 setup.py

转载 作者:行者123 更新时间:2023-12-01 07:06:55 25 4
gpt4 key购买 nike

我在同一个文件夹/包上有这些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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com