Title: Running setup.py install for Twisted … error ModuleNotFoundError: No module named 'twisted'
Tags: python;twisted
Question: I am trying to install twisted package from the source code. I have cloned the git repository and ran ```python3  setup.py build``` but it resulted in the error ```ModuleNotFoundError: No module named 'twisted'```. How to install the latest code? Pip install is not suitable as it has compatibility issues between Python3 and names module as mentioned in this post - Python Twisted pip package not compatible with Python3.

Comment: Hi, I am using Ubuntu 18 and trying to install twisted. I can make pip work if I use Python2, but Twisted has moved to Python3 in its latest source code but somehow did not update the pip module from 20.3 to whichever one supporting python 3. Their git repository tells to use pip3, but pip3 does not work for named module as told in the above link. So, I am trying to install the [latest source code](https://github.com/twisted/twisted/tree/twisted-20.11.0.dev5) by cloning the repository which is python3 compatible and using  `python3  setup.py` but ran into the above error.

Comment: Hello.  Welcome to Stack Overflow.  There is not enough information in your question to provide an answer.  Please provide a complete description of your environment and a complete transcript of your interaction.  Also, consider making pip work because pip is the correct way to install Python software and "python setup.py" is mostly the incorrect way.

Comment: There are many versions of pip.  "pip" and "pip3" do not clearly identify any particular version.  If you are using the Ubuntu 18-packaged version of pip (whether it is called "pip" or "pip3") then you probably need to upgrade.  I guess I can make an answer out of that.


Here is another answer: First create a &quot;virtualenv&quot;:
```virtualenv ~/playing-around-environment
```
Then activate it for your current shell:
```. ~/playing-around-environment
```
Then upgrade pip to get a version that deals with Python 2/3 distinctions better:
```pip install --upgrade pip
```
Then install Twisted into the virtualenv:
```pip install twisted
```
If you want to use a different version of Python, tell the virtualenv command at the beginning about it.  For example:
```virtualenv --python=python27 ~/playing-around-environment
```
or
```virtualenv --python=python38 ~/playing-around-environment
```
```python27``` or ```python38``` should give the name of a Python interpreter executable that's installed on your system.  The rest of the steps remain the same.

Comment for this answer: What I am trying to say is not about any issue with Pip or Python but about Twisted. On [Twisted GitHub webpage](https://github.com/twisted/twisted), they claim that it supports Python 3.5+, but that is not entirely true. I tried running `twistd -n dns --pyzone example-domain.com` after installing Twisted with Pip latest version on Ubuntu bionic, 20.2.4. That command gave the error `AttributeError: 'dict' object has no attribute 'iterkeys'` because Pip installed Twisted 20.3. So, how to install the latest Twisted version (20.11.5) by cloning their Git repository is my question?
Comment for this answer: Did you try installing into a virtualenv?

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:10/21/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><twisted>', 'Title': "Running setup.py install for Twisted … error ModuleNotFoundError: No module named 'twisted'", 'ViewCount': 472, 'id': 64465932, 'user_AboutMe': '', 'user_AccountId': 9243700.0, 'user_DisplayName': 'chester cheetah', 'user_Reputation': 83.0, 'user_Views': 13.0, 'user_id': 6866264.0}}