在 Windows 中从 bash 激活 python venv.如何解决行尾问题? [英] activating python venv from bash in Windows. How to resolve problem with line endings?

查看:29
本文介绍了在 Windows 中从 bash 激活 python venv.如何解决行尾问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 bash 脚本可以将一些代码部署到 AWS.它主要工作,但我在激活我的虚拟环境时遇到问题.这似乎与行尾有关,因为我正在尝试使用 Scripts/activate 激活 Windows venv.

I have a bash script to deploy some code to AWS. It mostly works but I'm having issues activating my virtual environment. It seems it might be to do with line endings because I'm trying to activate a windows venv using Scripts/activate.

我在日志中看到了以下类型的错误:

I see these types of errors in the logs:

Scripts/activate: line 3: $'\r': command not found脚本/激活:第 4 行:$'\r':找不到命令脚本/激活:第 10 行:意外标记附近的语法错误 `$'{\r''

Scripts/activate: line 3: $'\r': command not found Scripts/activate: line 4: $'\r': command not found Scripts/activate: line 10: syntax error near unexpected token `$'{\r''

我的脚本创建、安装软件包然后销毁 venv.如果我注释掉创建和销毁并将激活脚本的行尾更改为LF",它会起作用.那么如何在创建虚拟环境时强制使用 LF 结尾而不是 CRLF?

My script creates, installs packages then destroys the venv. If I comment out the creating and destroy and change the line endings of the activate script to 'LF' it works. So How can I force LF endings instead of CRLF on virtual env creation?

这是目前正在创建 env 的行:virtualenv $VENV

This is the line that is creating the env at the moment: virtualenv $VENV

推荐答案

用 dos2unix 命令修复

fixed with dos2unix command

dos2unix 脚本/激活

dos2unix Scripts/activate

这篇关于在 Windows 中从 bash 激活 python venv.如何解决行尾问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆