Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
3792 votes
14 answers
2.5m views

What is __init__.py for?

What is __init__.py for in a Python source directory?
Mat's user avatar
  • 85.2k
876 votes
10 answers
1.2m views

Can I force pip to reinstall the current version?

I've come across situations where a current version of a package seems not to be working and requires reinstallation. But pip install -U won't touch a package that is already up-to-date. I see how to ...
orome's user avatar
  • 47.6k
851 votes
10 answers
358k views

What's the difference between a module and package in Python?

What's the difference between a module and package in Python? See also: What's the difference between "package" and "module"? (for other languages)
Dave's user avatar
  • 9,293
842 votes
23 answers
664k views

How to fix "Attempted relative import in non-package" even with __init__.py

I'm trying to follow PEP 328, with the following directory structure: pkg/ __init__.py components/ core.py __init__.py tests/ core_test.py __init__.py In core_test.py I have ...
skytreader's user avatar
  • 11.6k
717 votes
13 answers
553k views

How do I remove packages installed with Python's easy_install?

Python's easy_install makes installing new packages extremely convenient. However, as far as I can tell, it doesn't implement the other common features of a dependency manager - listing and removing ...
ire_and_curses's user avatar
699 votes
23 answers
2.0m views

How to install pip with Python 3?

I want to install pip. It should support Python 3, but it requires setuptools, which is available only for Python 2. How can I install pip with Python 3?
deamon's user avatar
  • 91.3k
697 votes
4 answers
375k views

What is a Python egg?

I'm trying to understand how Python packages work. Presumably eggs are some sort of packaging mechanism, but what would be a quick overview of what role they play and may be some information on why ...
Bialecki's user avatar
  • 30.7k
595 votes
15 answers
708k views

beyond top level package error in relative import [duplicate]

It seems there are already quite some questions here about relative import in python 3, but after going through many of them I still didn't find the answer for my issue. so here is the question. I ...
shelper's user avatar
  • 10.4k
447 votes
24 answers
1.0m views

Python 3: ImportError "No Module named Setuptools"

I'm having troubles with installing packages in Python 3. I have always installed packages with setup.py install. But now, when I try to install the ansicolors package I get: importerror "No ...
user1994934's user avatar
  • 4,473
438 votes
19 answers
1.1m views

Relative imports - ModuleNotFoundError: No module named x

This is the first time I've really sat down and tried python 3, and seem to be failing miserably. I have the following two files: test.py config.py config.py has a few functions defined in it as ...
blitzmann's user avatar
  • 7,645
426 votes
5 answers
206k views

Is __init__.py not required for packages in Python 3.3+

I am using Python 3.5.1. I read the document and the package section here: https://docs.python.org/3/tutorial/modules.html#packages Now, I have the following structure: /home/wujek/Playground/a/b/...
wujek's user avatar
  • 10.7k
407 votes
32 answers
1.2m views

"pip install unroll": "python setup.py egg_info" failed with error code 1

I'm trying to install some packages with pip. But pip install unroll gives me Command "python setup.py egg_info" failed with error code 1 in C:\Users\MARKAN~1\AppData\Local\Temp\pip-build-...
benjaminh's user avatar
  • 4,079
388 votes
12 answers
240k views

Sibling package imports

I've tried reading through questions about sibling imports and even the package documentation, but I've yet to find an answer. With the following structure: ├── LICENSE.md ├── README.md ├── api │   ├...
zachwill's user avatar
  • 4,593
381 votes
6 answers
211k views

What is the purpose of the -m switch?

Could you explain to me what the difference is between calling python -m mymod1 mymod2.py args and python mymod1.py mymod2.py args It seems in both cases mymod1.py is called and sys.argv is ['...
Charles Brunet's user avatar
344 votes
13 answers
855k views

How do I update a Python package?

I'm running Ubuntu 9:10 and a package called M2Crypto is installed (version is 0.19.1). I need to download, build and install the latest version of the M2Crypto package (0.20.2). The 0.19.1 package ...
thompson's user avatar
  • 3,459
321 votes
10 answers
301k views

Does uninstalling a package with "pip" also remove the dependent packages?

When you use pip to install a package, all the required packages will also be installed with it (dependencies). Does uninstalling that package also remove the dependent packages?
Hossein's user avatar
  • 41.2k
265 votes
17 answers
297k views

Upgrade python packages from requirements.txt using pip command

How do I upgrade all my python packages from requirements.txt file using pip command? tried with below command $ pip install --upgrade -r requirements.txt Since, the python packages are suffixed ...
abhiomkar's user avatar
  • 4,808
252 votes
7 answers
148k views

How to read a (static) file from inside a Python package?

Could you tell me how can I read a file that is inside my Python package? My situation A package that I load has a number of templates (text files used as strings) that I want to load from within ...
ronszon's user avatar
  • 3,237
246 votes
3 answers
215k views

How do I write good/correct package __init__.py files

My package has the following structure: mobilescouter/ __init__.py #1 mapper/ __init__.py #2 lxml/ __init__.py #3 vehiclemapper.py ...
Marten Bauer's user avatar
  • 2,463
227 votes
16 answers
949k views

ModuleNotFoundError: No module named 'sklearn'

I want to import sklearn but there is no module apparently: ModuleNotFoundError: No module named 'sklearn' I am using Anaconda and Python 3.6.1; I have checked everywhere but still can't find ...
Hareez Rana's user avatar
  • 2,283
207 votes
3 answers
186k views

Execution of Python code with -m option or not [duplicate]

The python interpreter has -m module option that "Runs library module module as a script". With this python code a.py: if __name__ == "__main__": print __package__ print __name__ I tested ...
prosseek's user avatar
  • 188k
207 votes
15 answers
537k views

Can't import my own modules in Python

I'm having a hard time understanding how module importing works in Python (I've never done it in any other language before either). Let's say I have: myapp/__init__.py myapp/myapp/myapp.py myapp/...
user avatar
191 votes
15 answers
432k views

How to list all installed packages and their versions in Python?

Is there a way in Python to list all installed packages and their versions? I know I can go inside python/Lib/site-packages and see what files and directories exist, but I find this very awkward. ...
jsalonen's user avatar
  • 30.1k
191 votes
4 answers
144k views

Can I use __init__.py to define global variables?

I want to define a constant that should be available in all of the submodules of a package. I've thought that the best place would be in in the __init__.py file of the root package. But I don't know ...
Andrei Vajna II's user avatar
181 votes
21 answers
347k views

Check if Python Package is installed

What's a good way to check if a package is installed while within a Python script? I know it's easy from the interpreter, but I need to do it within a script. I guess I could check if there's a ...
Kevin's user avatar
  • 2,481
178 votes
4 answers
86k views

Does it make sense to use Conda + Poetry?

Does it make sense to use Conda + Poetry for a Machine Learning project? Allow me to share my (novice) understanding and please correct or enlighten me: As far as I understand, Conda and Poetry have ...
Seub's user avatar
  • 2,982
163 votes
5 answers
86k views

How do I create a namespace package in Python?

In Python, a namespace package allows you to spread Python code among several projects. This is useful when you want to release related libraries as separate downloads. For example, with the ...
joeforker's user avatar
  • 41.3k
157 votes
6 answers
80k views

Access data in package subdirectory [duplicate]

I am writing a python package with modules that need to open data files in a ./data/ subdirectory. Right now I have the paths to the files hardcoded into my classes and functions. I would like to ...
Jacob Lyles's user avatar
  • 10.3k
144 votes
8 answers
565k views

How to install Python packages from the tar.gz file without using pip install

Long story short my work computer has network constraints which means trying to use pip install in cmd just leads to timing out/not finding package errors. For example; when I try to pip install ...
yenoolnairb's user avatar
  • 1,613
142 votes
7 answers
213k views

How to import classes defined in __init__.py

I am trying to organize some modules for my own use. I have something like this: lib/ __init__.py settings.py foo/ __init__.py someobject.py bar/ __init__.py somethingelse.py ...
scottm's user avatar
  • 28.2k
138 votes
5 answers
59k views

Why #egg=foo when pip-installing from git repo

When I do a "pip install -e ..." to install from a git repo, I have to specify #egg=somename or pip complains. For example: pip install -e git://github.com/hiidef/oauth2app.git#egg=oauth2app What's ...
Lorin Hochstein's user avatar
137 votes
12 answers
167k views

Is there a standard way to list names of Python modules in a package?

Is there a straightforward way to list the names of all modules in a package, without using __all__? For example, given this package: /testpkg /testpkg/__init__.py /testpkg/modulea.py /testpkg/...
DNS's user avatar
  • 37.9k
135 votes
7 answers
113k views

List all the modules that are part of a python package?

Is there a straightforward way to find all the modules that are part of a python package? I've found this old discussion, which is not really conclusive, but I'd love to have a definite answer before ...
static_rtti's user avatar
  • 55.2k
133 votes
4 answers
128k views

Whats the difference between a module and a library in Python?

I have background in Java and I am new to Python. I want to make sure I understand correctly Python terminology before I go ahead. My understanding of a module is: a script which can be imported by ...
joker's user avatar
  • 2,073
129 votes
3 answers
210k views

Python: importing a sub‑package or sub‑module

Having already use flat packages, I was not expecting the issue I encountered with nested packages. Here is… Directory layout dir | +-- test.py | +-- package | +-- __init__.py |...
Hibou57's user avatar
  • 7,030
127 votes
13 answers
170k views

What is the most compatible way to install python modules on a Mac?

I'm starting to learn python and loving it. I work on a Mac mainly as well as Linux. I'm finding that on Linux (Ubuntu 9.04 mostly) when I install a python module using apt-get it works fine. I can ...
GloryFish's user avatar
  • 13.3k
124 votes
6 answers
164k views

Python: import module from another directory at the same level in project hierarchy

I've seen all sorts of examples and other similar questions, but I can't seem to find an example that exactly matches my scenario. I feel like a total goon asking this because there are so many ...
CptSupermrkt's user avatar
  • 6,994
117 votes
6 answers
52k views

pip install . creates only the dist-info not the package

I am trying to make a python package which I want to install using pip install . locally. The package name is listed in pip freeze but import <package> results in an error No module named <...
André Betz's user avatar
  • 1,451
115 votes
3 answers
80k views

Absolute vs. explicit relative import of Python module

I'm wondering about the preferred way to import packages in a Python application. I have a package structure like this: project.app1.models project.app1.views project.app2.models project.app1.views ...
Daniel Hepper's user avatar
108 votes
4 answers
44k views

Difference between entry_points/console_scripts and scripts in setup.py?

There are basically two ways to install Python console scripts to my path by setup.py: setup( ... entry_points = { 'console_scripts': [ 'foo = package.module:func', ...
Honza Javorek's user avatar
104 votes
4 answers
85k views

Adding code to __init__.py

I'm taking a look at how the model system in django works and I noticed something that I don't understand. I know that you create an empty __init__.py file to specify that the current directory is a ...
Erik's user avatar
  • 1,684
102 votes
5 answers
70k views

How include static files to setuptools - python package

I want to include the ./static/data.txt to setuptools, here is my code: # setup.py import os,glob from setuptools import setup,find_packages setup( name = "PotatoProject", version = "0.1.1", ...
joaoricardo000's user avatar
100 votes
6 answers
99k views

How do I list the files inside a python wheel?

I'm poking around the various options to setup.py for including non-python files, and they're somewhat less than intuitive. I'd like to be able to check the package generated by bdist_wheel to see ...
Andrew's user avatar
  • 4,248
92 votes
12 answers
375k views

Python: How to pip install opencv2 with specific version 2.4.9?

I know that I could pip install opencv-python which installs opencv3, but is there a separate command or name for opencv specific version such as 2.4.9? If not, how can I specify which version to ...
matchifang's user avatar
  • 5,380
91 votes
3 answers
38k views

How python deals with module and package having the same name?

Suppose I have a module foo.py and a package foo/. If I call import foo which one will be loaded? How can I specify I want to load the module, or the package?
Charles Brunet's user avatar
87 votes
5 answers
40k views

How to get the list of options that Python was compiled with?

You can compile Python in various ways. I'd like to find out with which options my Python was compiled. Concrete use-case: was my Python compiled with readline? I know I can see this by doing "import ...
Niels Bom's user avatar
  • 9,201
86 votes
3 answers
83k views

How to install my own python module (package) via conda and watch its changes

I have a file mysql.py, which I use in almost all of my projects. Since I do not want to copy and paste the same file into each of these projects I wrote a module - possibly a package in the future. ...
Michael's user avatar
  • 1,697
84 votes
4 answers
26k views

Check if requirements are up to date

I'm using pip requirements files for keeping my dependency list. I also try to follow best practices for managing dependencies and provide precise package versions inside the requirements file. For ...
alecxe's user avatar
  • 470k
80 votes
7 answers
77k views

jupyter notebook running kernel in different env

I've gotten myself into some kind of horrible virtualenv mess. Help?! I manage environments with conda. Until recently, I only had a python2 jupyter notebook kernel, but I decided to drag myself ...
Paul Gowder's user avatar
  • 2,519
77 votes
9 answers
35k views

How to upload new versions of project to PyPI with twine?

I've uploaded my Python package to PyPI. But now I made new version of my package and need to upload it. I tried to make same progress which I did when upload the package first time but I got the ...
Basel Akasha's user avatar
  • 1,228

1
2 3 4 5
76