Answer a question

I have python installed through windows store and I can install programs using pip, but when I try to run said programs, they fail to execute in powershell.

How can I make sure that the necessary "scripts" folder is in my path? I never faced these problems when installing from executable.

For example, "pip install ntfy" runs successfully in Powershell.

The command "ntfy send test" fails telling me the term is not part of a cmdlet, function, etc. etc.

The 'ntfy' program is located here /mnt/c/Users/vlouvet/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0/LocalCache/local-packages/Python37/Scripts/ntfy.exe

What is the recommended way of editing my path so that programs installed via pip are available across windows store updates of the Python language?

Answers

In advance

I highly recommend you not to use python installed from the Windows Store, because you'll face such errors, and even more nasty ones.

The easy solution

Create a virtual environment on a more accessible folder, for example in C:\Users\<user>\python. To do so, do the following:

  • Using PowerShell, go to your user folder, using cd(Note that usually PowerShell already starts inside your user folder. This is an important setting to have, and if not, you should change your powershell starting point to this folder for the future.);
  • Now that you're in your user folder, type in the PowerShell mkdir python; cd python;
  • Now, to create a virtual environment, type python -m venv venv;
  • (You can verify that your virtual enviroment has been created by listing the folders, with the command ls);
  • You have created a virtual environment. Now, you need to activate it. To activate, run the following: ./venv/Scripts/activate;

Now, you have fully created and activated a virtual environment for your current PowerShell session. You can now install any packages / programs using pip.

After that, the only thing that you need to do is to add C:\Users\<user>\python\venv\Scripts to your Path, and you're good to go.

Caveats

By adding this folder to your Path, you may be using an outdated python version in the future, since the Scripts folder inside your virtual environment also adds a python executable that will be enabled in the path.

The recommended solution

As I stated before, I do not recommend to have the Microsoft Store version of python installed on your machine. That said, you're probably using it for the conveniences of having the latest Python version installed as soon as they're released. To alleviate this need while also getting rid of your MS Store Python. I recommend you using Chocolatey to install python (and pretty much any other programs for development).

What is Chocolatey?

Chocolatey is a package manager for Windows, pretty much like apt-get for Ubuntu Linux or HomeBrew for MacOS. By using a package manager, you get rid of the hassle of always having to execute the (mostly annoying) install wizards on windows.

To install Chocolatey:

  • Go to chocolatey.org/install and follow the install instructions;
  • (Recommended: Take a look on their documentation later to see what Chocolatey is capable of);
  • With Chocolatey installed, take a test drive and see if it is working properly by running choco -v in PowerShell;
  • By having Chocolatey installed, you can now run choco install python -y. Let's break down this command:
    • choco install -> The package installer of chocolatey
    • python -> the name of the package you want to install
    • -y -> This tells the installer to skip install verification by saying "Yes to All" scripts that will be executed in order to install a package.
  • With python installed from chocolatey, you can also see that Python is already added to your path - This means that any python package or executable installed globally will be now available on your machine!

Hope I could help you!

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐