Search code examples
pythonpython-venv

Python Virtual Environment Activation Not Working


I am trying to activate a Python virtual environment on Windows and it seems like it took OK:

enter image description here

I installed a module I needed for my venv, but when I deactivate the venv, the module I just installed is still listed under pip list. I would have thought that after deactivating the venv, the module would no longer be considered "installed" since the venv is no longer active.

I tried the sys.prefix test and it returns False suggesting that I am not actually in my venv. I took a look at this link also.

Any ideas?


Solution

  • If module appears in pip list even after you deactivated the env, simply means that module was installed in Base Python Environment.

    It often happens when you work with env's quite frequently and sometimes you install something forgetting the env was not activated.

    Solution # 1

    One way is you can always pip uninstall <module> from you base or even any env.

    Solution # 2

    This solution will help you remove all non native Python Libraries without reinstalling Python from your device.

    • First take backup of every installed package.
    • Use pip freeze > uninstall.txt for Windows.
    • uninstall.txt will be used for backup plus removal as well
    • Then run this command
    • For windows for /F %i in (uninstall.txt) do pip uninstall -y %i
    • For Unix pip freeze | xargs pip uninstall -y

    Solution # 3

    You can always reinstall Python. hardly takes 2 mins :)