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

  • Home
  • SEARCH
  • 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 1038969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:02:31+00:00 2026-05-16T15:02:31+00:00

I am new to Python and mostly used my own code. But so now

  • 0

I am new to Python and mostly used my own code. But so now I downloaded a package that I need for some problem I have.

Example structure:

root\
    externals\
        __init__.py
        cowfactory\
            __init__.py
            cow.py
            milk.py

    kittens.py

Now the cowfactory’s __init__.py does from cowfactory import cow. This gives an import error.

I could fix it and change the import statement to from externals.cowfactory import cow but something tells me that there is an easier way since it’s not very practical.

An other fix could be to put the cowfactory package in the root of my project but that’s not very tidy either.

I think I have to do something with the __init__.py file in the externals directory but I am not sure what.

  • 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-05-16T15:02:31+00:00Added an answer on May 16, 2026 at 3:02 pm

    Inside the cowfactory package, relative imports should be used such as from . import cow. The __init__.py file in externals is not necessary. Assuming that your project lies in root\ and cowfactory is the external package you downloaded, you can do it in two different ways:

    1. Install the external module

      External Python packages usually come with a file “setup.py” that allows you to install it. On Windows, it would be the command “setup.py bdist_wininst” and you get a EXE installer in the “dist” directory (if it builds correctly). Use that installer and the package will be installed in the Python installation directory. Afterwards, you can simply do an import cowfactory just like you would do import os.

      If you have pip or easy_install installed: Many external packages can be installed with them (pip even allows easy uninstallation).

    2. Use PYTHONPATH for development

      If you want to keep all dependencies together in your project directory, then keep all external packages in the externals\ folder and add the folder to the PYTHONPATH. If you’re using the command line, you can create a batch file containing something like

      set PYTHONPATH=%PYTHONPATH%:externals
      yourprogram.py
      

      I’m actually doing something similar, but using PyDev+Eclipse. There, you can change the “Run configurations” to include the environment variable PYTHONPATH with the value “externals”. After the environment variable is set, you can simply import cowfactory in your own modules. Note how that is better than from external import cowfactory because in the latter case, it wouldn’t work anymore once you install your project (or you’d have to install all external dependencies as a package called “external” which is a bad idea).

    Same solutions of course apply to Linux, as well, but with different commands.

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

Sidebar

Related Questions

I'm new to Python... and coming from a mostly Java background, if that accounts
I have a PostgreSQL table that is mostly a bridge table but it also
I have been using Python for about a year now, coming from a mostly
In my code, I generate new python classes at runtime. For some of them,
I am new to Matplotlib and Python. I mostly use Matlab. Currently, I am
New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
Very new to python and can't understand why this isn't working. I have a
I am new to Python and have been studying its fundementals for 3 months
I'm a new to Python. I have installed Python 2.7 64 bit on Win7
Suppose a programmer has the following problem: he wants to start a new python

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.