Questions tagged [python-module]

A module is a file containing Python definitions and statements.

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.

2038 questions
23
votes
3 answers

Find the absolute path of an imported module

How can I get the absolute path of an imported module?
Determinant
  • 3,886
  • 7
  • 31
  • 47
22
votes
6 answers

How to install external modules in a Python Lambda Function created by AWS CDK?

I'm using the Python AWS CDK in Cloud9 and I'm deploying a simple Lambda function that is supposed to send an API request to Atlassian's API when an Object is uploaded to an S3 Bucket (also created by the CDK). Here is my code for CDK Stack: from…
Jamie
  • 1,530
  • 1
  • 19
  • 35
22
votes
5 answers

Python: OSError: [Errno 2] No such file or directory: ''

I have a 100 lines, 3 years old python scraper that now bug. Starting lines are: import urllib, re, os, sys, time # line 1: import modules os.chdir(os.path.dirname(sys.argv[0])) # line 2: all works in script's folder > relative address # (rest of…
Hugolpz
  • 17,296
  • 26
  • 100
  • 187
22
votes
1 answer

why __builtins__ is both module and dict

I am using the built-in module to insert a few instances, so they can be accessed globally for debugging purposes. The problem with the __builtins__ module is that it is a module in a main script and is a dict in modules, but as my script depending…
Anurag Uniyal
  • 85,954
  • 40
  • 175
  • 219
21
votes
5 answers

Collapse multiple submodules to one Cython extension

This setup.py: from distutils.core import setup from distutils.extension import Extension from Cython.Build import cythonize extensions = ( Extension('myext', ['myext/__init__.py', 'myext/algorithms/__init__.py', …
Reinderien
  • 11,755
  • 5
  • 49
  • 77
20
votes
2 answers

Importing from python modules inside parent directory into jupyter notebook files inside subdirectory

I have a file structure like this: project_folder/ notebooks/ notebook01.ipynb notebook02.ipynb ... notebookXY.ipynb module01.py module02.py module03.py In .ipynb files inside notebook/…
PeterB
  • 2,234
  • 6
  • 24
  • 43
20
votes
1 answer

Is it possible to import flask configuration values in modules without circular import?

I'm using Flask with Blueprints to get a skeleton for my website and I'm having a problem using configuration classes deep in my application. Here's some dummy code that explains how I've set everything up: websiteconfig.py class Config(object): …
moodh
  • 2,661
  • 28
  • 42
20
votes
6 answers

Python: determine actual current module (not __main__)

I'm trying to determine the actual current module of a function (as seen if imported from elsewhere), even if the current module is the "top level scripting environment" __main__. It may sound like a weird thing to do, but the background is that I…
soramimo
  • 1,296
  • 1
  • 13
  • 17
19
votes
1 answer

Pip install error missing 'libxml/xmlversion.h'

I need to install the python package xmlsec(https://pypi.python.org/pypi/xmlsec) and when I try running pip install xmlsec It gives me this error: src\xmlsec\constants.c(266) : fatal error C1083: Cannot open include file: 'libxml/xmlversion.h': No…
clue3434
  • 215
  • 1
  • 2
  • 8
19
votes
3 answers

How To Make Eclipse Pydev Plugin Recognize Newly Installed Python Modules?

So I just installed SubnetTree (http://www.icir.org/robin/pysubnettree/) and if I open the Python interactive interpreter I can successfully import it without any error messages. I use it in one of my programs and can successfully run it without a…
Stunner
  • 12,025
  • 12
  • 86
  • 145
19
votes
2 answers

How to use custom classes with Apache Spark (pyspark)?

I have written a class implementing a classifier in python. I would like to use Apache Spark to parallelize classification of a huge number of datapoints using this classifier. I'm set up using Amazon EC2 on a cluster with 10 slaves, based off an…
user3279453
  • 403
  • 1
  • 3
  • 12
19
votes
4 answers

Python libraries to calculate human readable filesize from bytes?

I find hurry.filesize very useful but it doesn't give output in decimal? For example: print size(4026, system=alternative) gives 3 KB. But later when I add all the values I don't get the exact sum. For example if the output of hurry.filesize is in…
pynovice
  • 7,424
  • 25
  • 69
  • 109
18
votes
6 answers

paramiko python module hangs at stdout.read()

I am using the below code: import paramiko def runSshCmd(hostname, username, password, cmd, timeout=None): client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(hostname,…
user3378508
  • 209
  • 1
  • 2
  • 8
18
votes
4 answers

Intellij/Pycharm can't debug Python modules

I use PyCharm/IntelliJ community editions from a wile to write and debug Python scripts, but now I'm trying to debug a Python module, and PyCharm does a wrong command line instruction parsing, causing an execution error, or maybe I'm making a bad…
Mariano Ruiz
  • 4,314
  • 2
  • 38
  • 34
18
votes
4 answers

Where are math.py and sys.py?

I found all the other modules in Python33/Lib, but I can't find these. I'm sure there are others "missing" too, but these are the only ones I've noticed. They work just fine when I import them, I just can't find them. I checked sys.path and they…
temporary_user_name
  • 35,956
  • 47
  • 141
  • 220