简体   繁体   English

没有 pyvenv.cfg 文件

[英]No pyvenv.cfg file

I made a variable cfg = waterot.cfg and then made a new file " waterot.cfg " in pycharm, this automatically made a pyvenv.cfg file, I didn't know what this was and I was getting errors with my code I deleted the pyvenv.cfg file and changed from .cfg to .txt .我创建了一个变量cfg = waterot.cfg ,然后在 pycharm 中创建了一个新文件“ waterot.cfg ”,这自动创建了一个pyvenv.cfg文件,我不知道这是什么,我删除的代码出现错误pyvenv.cfg文件并从.cfg更改为.txt Now when I run my code I get an error No pyvvenv.cfg file现在,当我运行代码时出现错误No pyvvenv.cfg file

This is the problematic piece of code这是有问题的代码

redeemkey = message.author
if redeemkey.startswith('!download'):
    if message.channel.id == 695834994064490658:
        with open ('waterOT.txt', 'rb') as otcfg:
            await message.author.send(file=discord.File(otcfg, 'waterOT.cfg'))
        await message.delete()

If you know the path for the python distribution used to create the virtual environment, and it's version, you can just create yourself a pyvenv.cfg file with following contents如果您知道用于创建虚拟环境的 python 发行版的路径及其版本,您可以自己创建一个包含以下内容的pyvenv.cfg文件

home = <location-of-python-exe>
include-system-site-packages = false
version = <version>

where在哪里

  • <location-of-python-exe> is the folder where the python.exe is located that was used to create the python virtual environment. <location-of-python-exe>python.exe所在的文件夹,用于创建 python 虚拟环境。 Example C:\Python\Python385-64 .示例C:\Python\Python385-64
  • <version> is the version of the python, at <location-of-python-exe> . <version>是 python 的版本,位于<location-of-python-exe> You can check it by running <location-of-python-exe>\python.exe .您可以通过运行<location-of-python-exe>\python.exe来检查它。 Example: 3.8.5 .示例: 3.8.5

Valid locations for the pyvenv.cfg are ( PEP405 ): pyvenv.cfg的有效位置是( PEP405 ):

  • Next to the python executable ( venv/Scripts/pyvenv.cfg ), ie in the same folder with python.exe .在 python 可执行文件 ( venv/Scripts/pyvenv.cfg ) 旁边,即与python.exe位于同一文件夹中。
  • One directory up from the python executable; python 可执行文件的上一级目录; root of the virtual environment ( venv/pyvenv.cfg )虚拟环境的根 ( venv/pyvenv.cfg )

where venv is the assumed name of the virtual environment (could be something else, too).其中venv是虚拟环境的假定名称(也可以是其他名称)。

the python.exe must be name like this. python.exe 必须是这样的名称。 I had py.exe and it did not work.我有 py.exe 但它不起作用。 Create the file: pyvenv.cfg and store it in the venv directory.创建文件:pyvenv.cfg,存放在venv目录下。

home = C:\Windows
include-system-site-packages = false
version = Flask 2.3.2 

pyvenv.cfg is a configuration file for a virtual environment . pyvenv.cfg虚拟环境的配置文件 Without knowing how you set things up, I assume Pycharm made the virtual environment .在不知道您如何设置的情况下,我假设Pycharm 制作了虚拟环境

You should not delete the pyvenv.cfg file if you want the virtual environment to work.如果您希望虚拟环境正常工作,则不应删除pyvenv.cfg文件。

With PyCharm you can restore that change in a couple of clicks:使用PyCharm ,您只需单击几下即可恢复该更改:

Right-click anywhere in the editor and choose Local History |右键单击编辑器中的任意位置并选择本地历史 | Show History from the context menu.从上下文菜单中显示历史

In the dialog that opens, the left-hand pane shows a list of all saved revisions of the current file with timestamps .在打开的对话框中,左侧窗格显示带有时间戳的当前文件的所有已保存修订的列表 The right-hand pane shows a diff viewer which displays the differences between each revision and the current state of the file.右侧窗格显示了一个差异查看器,其中显示了每个修订版与文件的当前 state 之间的差异。

OR或者

Do one of the following:执行以下操作之一:

To revert the whole file or directory to the state of this revision, right-click it and choose Revert from the context menu or click the Revert icon on the toolbar.要将整个文件目录恢复到此版本的 state,请右键单击它并从上下文菜单中选择恢复或单击工具栏上的恢复图标。

To restore a specific code fragment , select the revision that contains that fragment.恢复特定代码片段,请 select 包含该片段的修订版。 In the diff view on the right locate the piece of code you want to restore click the chevron button the Chevron button to copy it from the left pane.在右侧的差异视图中,找到要恢复的代码,单击 V 形按钮 V 形按钮从左侧窗格中复制它。

In my case I tried many ways, but finally I do one thing that solve my error.就我而言,我尝试了很多方法,但最后我做了一件事来解决我的错误。 I just delete existing venv directory and set Project Interpreter from my editor.我只是删除现有的venv目录并从我的编辑器中设置项目解释器。 PyCharm Editor Setting Thanks PyCharm 编辑器设置谢谢

The easiest way is to chose 'file' in left hand corner of pycharm window, then choose restart IDE, then follow the steps of restarting settings of IDE. The easiest way is to chose 'file' in left hand corner of pycharm window, then choose restart IDE, then follow the steps of restarting settings of IDE. It worked for me.它对我有用。

I was starting a process on Windows as a different user with some ugly pywin32 code, when I ran into No pyvenv.cfg file with return code 106 from the python.exe inside of my venv.我在 Windows 上作为一个不同的用户使用一些丑陋的 pywin32 代码启动了一个进程,当我遇到No pyvenv.cfg file时,我的 venv 中的python.exe返回代码为 106。

Long story short, I fixed it by replacing the relative path to the exe with an absolute path.长话短说,我通过用绝对路径替换 exe 的相对路径来修复它。

  • Relative path (bad): venv\Scripts\python.exe相对路径(错误): venv\Scripts\python.exe
  • Absolute path (good): C:\...\venv\Scripts\python.exe绝对路径(好): C:\...\venv\Scripts\python.exe

I tried to read the above solutions but did not understand.我试图阅读上述解决方案但不明白。 I uninstalled Python and reinstalled it again , and everything worked well.卸载了 Python 并重新安装了一遍,一切正常。 The error disappeared.错误消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM