I'm a beginner in Arch Linux, and I wanted to use Sanic in my Python project. From the Package Management, I learned that pip has been disabled on Arch Linux, therefore I tried using the pacman -S python-sanic
command and successfully installed Sanic.
Bud when I wanted to install the sanic-cors, I had encountered a problem: which name I should use, python-sanic-cors
or python-sanic_cors
I tried both of them, but the Pacman can't find them. I removed the python-
, but it didn't work.
Finally, I used yay sanic-cors
, and it worked.
However, I am not sure if this installation method is accurate, or if I have truly installed the sanic-cors package for Python.
When I run the code:
# api.py
from sanic import Sanic, json
from sanic_cors import CORS
app = Sanic("ip")
CORS(app)
@app.route("/get_proxy")
async def ip_api(request):
ip = "XXXXXX"
return json({"ip": ip})
def start_server():
app.run(host="127.0.0.1", port=5050)
if __name__ == '__main__':
start_server()
PyCharm reported an error:
Traceback (most recent call last):
File "/home/jebhim/PycharmProjects/MyProject/api.py", line 2, in <module>
from sanic import Sanic, json
File "/usr/lib/python3.12/site-packages/sanic/__init__.py", line 3, in <module>
from typing_extensions import TypeAlias
ModuleNotFoundError: No module named 'typing_extensions'
No matter what pacman or yay command I use, I am unable to install this missing module.
All in all, I want to know how to accurately install Python packages? Should I use pip, pacman or yay?
If I should use Pacman,how should I correctly convert the name of a Python package to an AUR package name for my installation? Is it necessary to add the python-
prefix? If I don't add it, could I end up downloading some strange packages?
Here are the details about my operating system and Python-related information, if you need them.
Arch linux:
OS: Arch Linux x86_64
Kernel: 6.11.4-arch1-1
Shell: bash 5.2.37
DE: Plasma 6.2.1
Python:
Python 3.12.7
It seems you are a bit confused with different ways to install python packages. I will try to answer by steps, but first of all you should have clear the concept of a package manager. Practically speaking, a package manager is a program which is used for installing programs or libraries, more generally known as packages, from remote repositories along with their own set of prerequisites (also known as requirements). pacman
and pip
are two completely different package managers, thus they work on different remote repositories. yay
is a program that installs packages from a repository called Arch User Repository (or AUR), and I must confess I don't know if it's a completely independent repository or it is somewhat integrated with the default arch repositories.
Given this quick introduction, I will answer your questions:
pip
is not disabled on Arch Linux: the page you link does not state that at all. If you want to use pip
you need to install the package python-pip
from the Arch Linux package repository (i.e. run pacman -S python-pip
). This will make available to you a program called pip
, which is the package manager for python packages.
By running yay sanic-cors
you effectively installed the package sanic-cors
and this can be also seen from the error that you posted, in which the module typing_extensions
is missing and not sanic
. This may be an error of the package (missing prerequisites in the package description -- i.e. the recipe used for creating the package).
By the way, that module exists in Arch Linux and can be installed by using pacman -S python-typing_extensions
.
Now, I generally follow this rule about the python packages I install:
pacman
(Arch) or apt
(Debian/Ubuntu)) for broadly used packages in the entire system (like numpy
or matplotlib
. In order to look for python packages distributed by Arch, use the default Arch repositories search bar or the AUR search bar. You can do the same by using pacman -Ss <search query>
for the former repositories or yay -Ss <search query>
for the AUR.pip
inside the environment. You can think of a virtual environment as an isolated container of python packages that are available only inside the environment. You get inside the environment by sourcing a file of your environment (source environment/bin/activate
) and you get out with the deactivate
bash function.