I'm trying to install the discord-1.7.3 package. pip installs discord-1.7.3 and discord.py-2.0.1. My program is incompatible with version 2.x.x so I need only version 1.7.3 to install. The answers to this question suggest telling pip what version to install, but this doesn't work:

$ python3 --versionPython 3.9.2$ pip install 'discord==1.7.3'Collecting discord==1.7.3Using cached discord-1.7.3-py3-none-any.whl (1.1 kB)Collecting discord.py>=1.7.3Using cached discord.py-2.0.1-py3-none-any.whl (1.1 MB)Requirement already satisfied: aiohttp<4,>=3.7.4 in /home/username/.local/lib/python3.9/site-packages (from discord.py>=1.7.3->discord==1.7.3) (3.8.1)Requirement already satisfied: multidict<7.0,>=4.5 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (6.0.2)Requirement already satisfied: attrs>=17.3.0 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (22.1.0)Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (4.0.2)Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (2.1.1)Requirement already satisfied: aiosignal>=1.1.2 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (1.2.0)Requirement already satisfied: yarl<2.0,>=1.0 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (1.8.1)Requirement already satisfied: frozenlist>=1.1.1 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (1.3.1)Requirement already satisfied: idna>=2.0 in /home/username/.local/lib/python3.9/site-packages (from yarl<2.0,>=1.0->aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (3.3)Installing collected packages: discord.py, discordSuccessfully installed discord-1.7.3 discord.py-2.0.1

... you see discord.py-2.0.1 was installed anyway.

This answer suggests using pkg_resources to control what version is imported, but that doesn't work either:

$ cat test.pyimport pkg_resourcespkg_resources.require("discord==1.7.3")import discordprint(discord.version_info)$ python3 test.pyVersionInfo(major=2, minor=0, micro=1, releaselevel='final', serial=0)
1

Best Answer


"How to only install (or import) a specific package version?" is the wrong question in this case.

You don't want to install the discord package at all, since it's just a mirror/placeholder.

This is a mirror package!
It is recommended to install discord.py instead.

If you want version 1.7.3 of Discord.py, then install the correct package:

pip install discord.py==1.7.3

In fact, the discord placeholder package doesn't even contain any code:

$ unzip -l discord-2.0.0-py3-none-any.whlArchive: discord-2.0.0-py3-none-any.whlLength Date Time Name--------- ---------- ----- ----381 08-20-2022 23:51 discord-2.0.0.dist-info/METADATA92 08-20-2022 23:51 discord-2.0.0.dist-info/WHEEL1 08-20-2022 23:51 discord-2.0.0.dist-info/top_level.txt296 08-20-2022 23:51 discord-2.0.0.dist-info/RECORD

All it does is require discord.py>=2.0.0:

$ unzip -p discord-2.0.0-py3-none-any.whl discord-2.0.0.dist-info/METADATAMetadata-Version: 2.1Name: discordVersion: 2.0.0Summary: A mirror package for discord.py. Please install that instead.Home-page: https://github.com/Rapptz/discord.pyAuthor: RapptzLicense: UNKNOWNPlatform: UNKNOWNDescription-Content-Type: text/markdownRequires-Dist: discord.py (>=2.0.0)