Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to only install (or import) a specific version of discord.py?

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 --version
Python 3.9.2
$ pip install 'discord==1.7.3'
Collecting discord==1.7.3
  Using cached discord-1.7.3-py3-none-any.whl (1.1 kB)
Collecting discord.py>=1.7.3
  Using 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, discord
Successfully 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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$ cat test.py
import pkg_resources
pkg_resources.require("discord==1.7.3")
import discord

print(discord.version_info)

$ python3 test.py
VersionInfo(major=2, minor=0, micro=1, releaselevel='final', serial=0)

>Solution :

"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.whl
Archive:  discord-2.0.0-py3-none-any.whl
  Length      Date    Time    Name
---------  ---------- -----   ----
      381  08-20-2022 23:51   discord-2.0.0.dist-info/METADATA
       92  08-20-2022 23:51   discord-2.0.0.dist-info/WHEEL
        1  08-20-2022 23:51   discord-2.0.0.dist-info/top_level.txt
      296  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/METADATA
Metadata-Version: 2.1
Name: discord
Version: 2.0.0
Summary: A mirror package for discord.py. Please install that instead.
Home-page: https://github.com/Rapptz/discord.py
Author: Rapptz
License: UNKNOWN
Platform: UNKNOWN
Description-Content-Type: text/markdown
Requires-Dist: discord.py (>=2.0.0)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading