Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about pip using Python from Windows Store

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?

like image 751
vicente louvet Avatar asked Aug 08 '19 23:08

vicente louvet


People also ask

Where does Python install from Windows Store?

Python will be installed into the Program Files directory. The Python Launcher for Windows will be installed into the Windows directory.

Should I install Python from Windows Store?

For beginners who are new to Python, we recommend you install Python from the Microsoft Store. Installing via the Microsoft Store uses the basic Python3 interpreter, but handles set up of your PATH settings for the current user (avoiding the need for admin access), in addition to providing automatic updates.

Where pip is installed on Windows?

In Windows, the PIP configuration file is %HOME%\pip\pip.ini. There is also a legacy per-user configuration file. The file is located at %APPDATA%\pip\pip.ini . You can set a custom path location for this config file using the environment variable PIP_CONFIG_FILE .

Is pip installed by default with Python?

Key terms. pip is the preferred installer program. Starting with Python 3.4, it is included by default with the Python binary installers. A virtual environment is a semi-isolated Python environment that allows packages to be installed for use by a particular application, rather than being installed system wide.


3 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!

like image 141
Werberth Lins Avatar answered Oct 17 '22 07:10

Werberth Lins


The above answer is good but I managed to get it to work by doing the following.

  1. Find your installation under C:\Users\"your user"\AppData\Local\Packages it will be named something like PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0
  2. Open your windows settings in the start menu
  3. In search type Environment variables. Edit environment variables for your account should pop up. Click it
  4. In the top box find Path, click it
  5. On the right Click new and enter C:\Users\"your user"\AppData\Local\Packages\"python install directory name from 1. here"\LocalCache\local-packages\Python37\Scripts inside the little box under the last item in the list
  6. open a new cmd prompt and type the script you wanted it should work.
like image 31
nkassis Avatar answered Oct 17 '22 08:10

nkassis


On Windows you can find the user base binary directory by running

python -m site --user-site

and replacing site-packages with Scripts.

For example, this could return

C:\Users\Username\AppData\Roaming\Python36\site-packages

so you would need to set your PATH to include

C:\Users\Username\AppData\Roaming\Python36\Scripts

You can set your user PATH permanently in the Control Panel. You may need to log out for the PATH changes to take effect.

like image 45
Mike Lee Avatar answered Oct 17 '22 08:10

Mike Lee