与VENV一起在WSL中安装Python要求的问题

发布于 2025-01-30 14:55:38 字数 1011 浏览 3 评论 0原文

完全相同的方式来设置我的本地系统,

我有一个来自供应商的代码存储库,我正在尝试以与他们已经在Windows中使用WSL的Ubuntu 所以我想我会尝试尝试还将此系统用于此供应商回购。在存储库中,有一个看起来像这样的shell脚本:

#!/bin/bash
cd /home/vendorname/vendor-app
. /home/vendorname/.virtualenvs/vendor-app/bin/activate
. /home/vendorname/vendor-app/vendor-environment.sh
python3 /home/vendorname/vendor-app/vendor_script.py

对于参数的情况,让我们称此文件为“ runner.sh”

。将通过家庭下面的Vendorname文件夹的位置建议。不确定这是否是一个问题,但可能是。

其次,我已经设置了我的文件结构与此shell脚本似乎所示的完全相同。我已经将代码存储库放在/home/vendorname下,并使用VENV在/home/vendorname/.virtualenvs/vendor-app下创建了一个虚拟环境。

我还使用以下命令激活了我的虚拟环境:

source /home/vendorname/.virtualenvs/vendor-app/bin/activate

我的问题

从命令行运行runner.sh文件时

Traceback (most recent call last):
  File "/home/vendorname/vendor-app/vendor_script.py", line 17, in <module>
    import requests
ModuleNotFoundError: No Module named 'requests'

我会收到以下错误:此错误似乎指示未安装请求模块,但是每当我尝试安装时我得到了“已经满足的需求”响应。

有什么想法吗?

I have a code repository from a vendor and I'm trying to set up my local system in the exact same way that they did (as much as possible)

I'm running Ubuntu in WSL for Windows already so I figured I would try to also use this system for this vendor repo. In the repo there is a shell script which looks like this:

#!/bin/bash
cd /home/vendorname/vendor-app
. /home/vendorname/.virtualenvs/vendor-app/bin/activate
. /home/vendorname/vendor-app/vendor-environment.sh
python3 /home/vendorname/vendor-app/vendor_script.py

For case of argument, lets call this file "runner.sh"

First thing to note here is that I do not have a user in my Ubuntu/WSL called 'vendorname' as would be suggested by the location of the vendorname folder under home. Not sure if that is an issue but it might be.

Second, I have set up my file structure exactly the same as this shell script seems to indicate. I have placed my code repository under /home/vendorname and I have used venv to create a virtual environment located under /home/vendorname/.virtualenvs/vendor-app.

I have also activated my virtual environment with the following command:

source /home/vendorname/.virtualenvs/vendor-app/bin/activate

My problem

When I run the runner.sh file from the command line I get the following error:

Traceback (most recent call last):
  File "/home/vendorname/vendor-app/vendor_script.py", line 17, in <module>
    import requests
ModuleNotFoundError: No Module named 'requests'

This error seems to indicate that the requests module is not installed however whenever I try to install it I get the "Requirement already satisfied" response.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

好菇凉咱不稀罕他 2025-02-06 14:55:39

问题在Shell脚本的第3行中:

#!/bin/bash
cd /home/vendorname/vendor-app
. /home/vendorname/.virtualenvs/vendor-app/bin/activate
. /home/vendorname/vendor-app/vendor-environment.sh
python3 /home/vendorname/vendor-app/vendor_script.py

应该看起来像这样:

#!/bin/bash
cd /home/vendorname/vendor-app
. source /home/vendorname/.virtualenvs/vendor-app/bin/activate
. /home/vendorname/vendor-app/vendor-environment.sh
python3 /home/vendorname/vendor-app/vendor_script.py

不确定这是如何工作的,但在本地解决了我的问题

The problem was in line 3 of the shell script:

#!/bin/bash
cd /home/vendorname/vendor-app
. /home/vendorname/.virtualenvs/vendor-app/bin/activate
. /home/vendorname/vendor-app/vendor-environment.sh
python3 /home/vendorname/vendor-app/vendor_script.py

Which should have looked like this:

#!/bin/bash
cd /home/vendorname/vendor-app
. source /home/vendorname/.virtualenvs/vendor-app/bin/activate
. /home/vendorname/vendor-app/vendor-environment.sh
python3 /home/vendorname/vendor-app/vendor_script.py

Not sure how this ever worked but that fixed my problem locally

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文