python-module

How to move all modules to new version of Python (from 3.6 to 3.7)

How to move all modules to new version of Python (from 3.6 to 3.7) Question: I just upgraded to python 3.7 and I realized that all my modules stuck with the previous version. Even Django is not recognised anymore. How can I do to transfer everything to the new version? I am a little lost …

Total answers: 7

Python: replacing a function within a class of a module

Python: replacing a function within a class of a module Question: I’m trying to replace a function defined within a class in order to modify its function (as in inner workings) without changing the actual code. I’ve never done this before, and, hence, am having some problems while replacing it. Changing the code will have …

Total answers: 5

How to import a module from a different folder?

How to import a module from a different folder? Question: I have a project which I want to structure like this: myproject ├── api │ ├── __init__.py │ └── api.py ├── backend │ ├── __init__.py │ └── backend.py ├── models │ ├── __init__.py │ └── some_model.py └── __init__.py Now, I want to import the module …

Total answers: 3

ImportError: libSM.so.6: cannot open shared object file: No such file or directory

ImportError: libSM.so.6: cannot open shared object file: No such file or directory Question: When trying to import OpenCV, using import cv2 I get the following error: /usr/local/lib/python2.7/dist-packages/cv2/__init__.py in <module>() 7 8 # make IDE’s (PyCharm) autocompletion happy —-> 9 from .cv2 import * 10 11 # wildcard import above does not import “private” variables like …

Total answers: 9

How to debug a Python module run with python -m from the command line?

How to debug a Python module run with python -m from the command line? Question: I know that a Python script can be debugged from the command line with python -m pdb my_script.py if my_script.py is a script intended to be run with python my_script.py. However, a python module my_module.py should be run with python …

Total answers: 6

Can't find "matplotlib.markers" even with Matplotlib installed

Can't find "matplotlib.markers" even with Matplotlib installed Question: I realize this seems like a generic question, but all answers pointed to having two simultanious python installations – I already uninstalled the other one. Currently I run my code from PyCharm 2017.1.5 (windows 10) with Python interpreter set as Python 3.6.1 (C:Anaconda3python.exe), i.e. I installed Anaconda3, …

Total answers: 5

Why do I need __init__.py at every level?

Why do I need __init__.py at every level? Question: Given that I have the following directory structure with . being the current working directory . —foo —bar —__init__.py —baz.py When I run python -c “import foo.bar.baz” I get Traceback (most recent call last): File “<string>”, line 1 ImportError: No module named foo.bar.baz If I echo …

Total answers: 1

python calling a module that uses argparser

Python calling a module that uses argparser Question: This is probably a silly question, but I have a python script that current takes in a bunch of arguments using argparser and I would like to load this script as a module in another python script, which is fine. But I am not sure how to …

Total answers: 3

Python unittest – Ran 0 tests in 0.000s

Python unittest – Ran 0 tests in 0.000s Question: So I want to do this code Kata for practice. I want to implement the kata with tdd in separate files: The algorithm: # stringcalculator.py def Add(string): return 1 and the tests: # stringcalculator.spec.py from stringcalculator import Add import unittest class TestStringCalculator(unittest.TestCase): def add_returns_zero_for_emptyString(self): self.assertEqual(Add(‘ ‘), …

Total answers: 7