简体   繁体   中英

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.. ). 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.

(Note: this isn't about how to integrate a virtualenv in project, I've already done that)

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 ).

  • My shell rcfile (at user/learnp/project1 ) override file looks like this:

     source ~/.bashrc source ~/learnp/project1/venv/bin/activate 
  • In PyCharm Preferences → Tools → Terminal, my Shell Path adjustment looks like this:

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

[previously: /bin/bash]

  • When I launch my Terminal in PyCharm, this is what I see:

     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.

How can I fix this? what did I do wrong?

According to the blog post that you linked, the .pycharm-bash has the line:

source ~/.bashrc

This instructs your shell execute the /User/user/.bashrc file within it's current context. 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 :

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

These lines mean 'source the file /User/<current user>/.bashrc if it exists, otherwise do nothing.'

I would suggest that you take a look at what bashrc does, as it is an important part of programming in the Unix environment. This answer can shed some light on what the file does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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