【发布时间】:2022-01-07 00:58:39
【问题描述】:
我可以访问一个包含以下分支的私有 GitLab 项目:main、develop 和 new_branch。机器学习项目非常复杂,包含用于 NLP 的各种转换器,以及从输入文本生成一些输出的许多步骤。也使用了 FastAPI。
我正在尝试看看它是如何工作的并运行它。我使用 Windows。我知道我需要 Python 3.9 并安装 pipenv,然后给出以下说明:
Install all dependencies locally by running `pipenv install --dev`.
Create an empty file named `.env` inside the root project folder.
Copy and paste the contents of the `.env.example` file into `.env`.
Run `pipenv run prebuild-win` to download the necessary static files needed by 3rd party libraries.
Run API using the following command: `pipenv run start`. Go to `http://localhost:8000/`.
我打开 git CMD,克隆它,它是文件夹中出现的 develop 分支(对于 new_branch,它显示为 Pipeline: failed)。我导航到项目的文件夹,创建了一个虚拟环境并安装了依赖项。 GitLab 中名为 .env.example 的文件已经以 .env 的形式出现在我的文件夹中,其中包含必要的内容。我运行 pipenv run prebuild-win 并安装其他所有内容。
但是当我使用pipenv run start 运行 API 时,我得到:
Traceback (most recent call last):
File "C:\Users\me\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\me\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\me\the-project\app\main.py", line 25, in <module>
api = Api()
File "C:\Users\me\the-project\app\main.py", line 13, in __init__
self.config_service = ConfigService()
File "C:\Users\me\the-project\app\core\config.py", line 17, in __init__
self.port = int(os.getenv('PORT'))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
我做错了什么吗?
我检查并有一个端口,我认为这是因为我跳过了创建.env 文件的步骤。我创建了一个空文本文件,复制并粘贴了内容,我得到了同样的错误。 .env.example 包含:
APP_NAME=My app
VERSION=0.0.1
HOST=127.0.0.1
PORT=1234
【问题讨论】:
-
@abc 我看到了这个问题,我确实有一个端口。我对问题添加了编辑。我认为问题不在于创建该 .env 文件。但我现在确实创建了它,但我得到了同样的错误。
-
@abc 所以我设法完成了这一步,但现在如果我去 localhost 我只会得到 {"name":"My app","version":"0.0.1","当前时间":"01/07/2022, 04:11:55"}