Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8096711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:32:08+00:00 2026-06-05T21:32:08+00:00

I have a setup.py that needs to support both Python 2 and 3. The

  • 0

I have a setup.py that needs to support both Python 2 and 3.

The code currently works and is installable in Python 2.x

If I add the use_2to3 = True clause to my setup.py, then the module can be installed in Python 3, however, doing a:

python setup.py test

Causes a failure as one of the tests uses the StringIO class, and the import line goofs in Python 3 (it’s currently from StringIO import StringIO, where in Python3 it should be from io import StringIO

I thought though that once you add the use_2to3 keyword all tests (including unittests) were processed by 2to3 before being tested.

What am I missing? In case it helps, the bulk of my setup.py looks like:

from setuptools import setup

setup(
    name='myproject',
    version='1.0',
    description='My Cool project',
    classifiers = [
        'Programming Language :: Python',
        'Programming Language :: Python :: 3',
    ],

    py_modules=['mymodule'],
    test_suite='test_mymodule',
    zip_safe=False,
    use_2to3 = True,
)

Edit: the reason I feel as though 2to3 isn’t getting run on a python setup.py test is that it blows up & the bottom of the stacktrace reads:

File "/home/aparkin/temp/mymodule/test_mymodule.py", line 18, in <module>
    from StringIO import StringIO

But if I ran 2to3 on test_mymodule.py, then that import line should’ve been reworked to:

from io import StringIO

And (at worst) the tests should just individually fail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:32:10+00:00Added an answer on June 5, 2026 at 9:32 pm

    In order for distribute to pick your module up and run in through 2to3, it must be listed in py_modules. So change that to:

    py_modules=['mymodule', 'test_mymodule'],
    

    Unfortunately this has a side-effect of installing test_mymodule when you install the project, which you probably did not want. For cases like this I will generally convert the project into a package with a mymodule.tests sub-package. This way the tests can be “installable” without adding additional clutter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a setup function that runs onload to add some behaviours to elements.
I have a site setup that is working fine in ie8 and firefox but
I have a setup project that installs my app to the typical program files
I have an Setup project that installs App.exe. App.exe depends on 1) A third
I have a setup application that if user clicks the same setup twice, they
I'm running wamp on Vista (Apache v2.2.11) and have projects setup such that http://localhost/projectx
I have a product setup executable that copies some files to the user's hard
I have a Inno Setup project that I want to check if the application
I have setup an android test project that runs junit tests. It's using two
I have a parent-child relationship setup that is fairly basic. The end result is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.