activate virtualenv in git bash using pycharm on windows

Stack Overflow Asked by Mostafa Ghadimi on January 1, 2022

I have activated git bash instead of command prompt (cmd) in Pycharm. Whenever I try to activate the virtualenv, which is named venv, I face with two problems:

  1. After I execute source venv/Scripts/activate, face with the following error:
bash: basename: command not found

which (I think) means that it doesn’t recognize source command.

  1. Running ./venv/Scripts/activate has also another problem:
You must source this script: $ source ./venv/Scripts/activate

What should I do?

pycharm terminal

PS: Also <exact-directory>/venv/Scripts/activate works properly in cmd.

4 Answers

just write this command line in your virtual environment file:

. Scripts/activate

Answered by zeki kadiroğlu on January 1, 2022

The correct answer appears to be in the comment added by @Touten.

This is actually just a display issue - the venv is activated, but it doesn't display the usual (venv) tag in the terminal. This can be confirmed by calling which python and seeing that is displays the venv's python.

Alternatively, you can follow the answer by @Nikki-Aaron to disable automatically activating the venv. Then you can activate it using source venv/Scripts/activate and it will show the tag in the terminal.

Answered by Further Reading on January 1, 2022

There is a setting in File > Settings > Terminal for "Activate virtualenv". This works for cmd shell, but seems not to work with bash in Windows 10. If I uncheck that setting, 'source venv/Scripts/activate' activates as expected.

Answered by Nikki on January 1, 2022

There is a python package called pipenv.

It can be installed easily by entering pip install pipenv command. Then start using it by executing the following command:

pipenv shell

It automatically creates a new virtual environment.

Freezing the packages is as simple as:

pipenv lock -r > requirements.txt

Answered by Mostafa Ghadimi on January 1, 2022

Add your own answers!

Related Questions

Serialise array as single XML element in C#

1  Asked on January 25, 2021 by david-poxon


How to Create a Function to extract data from a JSON file

1  Asked on January 25, 2021 by ineedhelp


SQL create aggregated result from 2 queries

2  Asked on January 25, 2021 by sudhishkr


Mongoose : find document with subdocument filter

1  Asked on January 25, 2021 by temp_user


problems with @binding between structs

1  Asked on January 24, 2021 by mateus-neves


Testing Saga using Jest that have other module dependencies

0  Asked on January 24, 2021 by mzafer


mysql join 3 table but the “COUNT” be duplicate

1  Asked on January 24, 2021 by faisal-budiman


FTPS failing, but only on some commands on some machines

1  Asked on January 24, 2021 by watyf


Differently displayed colors on chart.js

3  Asked on January 24, 2021 by leos-literak


Vue Js Dynamic Class Binding Not Updating

2  Asked on January 24, 2021 by niall-parker


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP