简体   繁体   English

PyCharm:“ bash:/Users/user/.bashrc:没有此类文件或目录”

[英]PyCharm: “bash: /Users/user/.bashrc: No such file or directory”

I'm trying to follow this SO answer and this blog post to activate my virtualenv automatically in PyCharm's Terminal (no need for source path, etc.. ). 我正在尝试遵循该SO答案此博客文章,以在PyCharm的Terminal中自动激活我的virtualenv(无需source path, etc.. )。 The difference in my case is that my virtualenv folder resides in my project's root folder, and that's where I want the shell --rcfile to be as well. 在我的情况下,不同之处在于我的virtualenv文件夹位于项目的根文件夹中,这也是我希望shell --rcfile所在的位置。

(Note: this isn't about how to integrate a virtualenv in project, I've already done that) (注意:这不是关于如何将virtualenv集成到项目中,我已经做到了)

After many retries, I got it to work, however with a quibble that I'm not sure that I should live with. 经过多次重试后,我开始使用它了,但是有一个疑问,我不确定是否应该忍受。 Here are my configurations: 这是我的配置:

  • My virtualenv lives in a /venv/ directory at the root folder of my project (called project1 ). 我的virtualenv位于我项目的根文件夹(称为project1 )的/venv/目录中。

  • My shell rcfile (at user/learnp/project1 ) override file looks like this: 我的shell rcfile(位于user/learnp/project1 )覆盖文件如下所示:

     source ~/.bashrc source ~/learnp/project1/venv/bin/activate 
  • In PyCharm Preferences → Tools → Terminal, my Shell Path adjustment looks like this: 在PyCharm首选项→工具→终端中,我的Shell Path调整如下所示:

     /bin/bash --rcfile ~/learnp/project1/h.pycharm-bash 

[previously: /bin/bash] [以前:/ bin / bash]

  • When I launch my Terminal in PyCharm, this is what I see: 当我在PyCharm中启动我的终端时,这是我看到的:

     bash: /Users/user/.bashrc: No such file or directory (venv)bash-3.2$ 

So venv is activated, however two things I find worrying is that it's saying there isn't a file name bashrc, and that the prompt is saying bash-3.2 instead of showing the regular Terminal prompt with my username in it. 所以venv被激活了,但是我发现担心的两件事是它说没有文件名bashrc,并且提示说的是bash-3.2而不是显示带有我的用户名的常规Terminal提示。

How can I fix this? 我怎样才能解决这个问题? what did I do wrong? 我做错了什么?

According to the blog post that you linked, the .pycharm-bash has the line: 根据您链接的博客文章, .pycharm-bash行如下:

source ~/.bashrc

This instructs your shell execute the /User/user/.bashrc file within it's current context. 这指示外壳/User/user/.bashrc file在当前上下文中执行/User/user/.bashrc file The problem for you is that this file doesn't exist. 您的问题是此文件不存在。

The best way to deal with this problem is by adding these lines to .pycharm-bash : 解决此问题的最佳方法是将这些行添加到.pycharm-bash

if [ -e ~/.bashrc ]
then
    source ~/.bashrc
fi

These lines mean 'source the file /User/<current user>/.bashrc if it exists, otherwise do nothing.' 这些行的意思是“如果文件/User/<current user>/.bashrc存在,则将其作为源,否则不执行任何操作。”

I would suggest that you take a look at what bashrc does, as it is an important part of programming in the Unix environment. 我建议您看一下bashrc功能,因为它是Unix环境中编程的重要组成部分。 This answer can shed some light on what the file does. 这个答案可以使您了解文件的功能。

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

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