python-module

Why does simply importing a python module executes everything present in that module ? [duplicate]

喜欢而已 提交于 2020-01-03 18:33:13
问题 This question already has answers here : Why is Python running my module when I import it, and how do I stop it? (9 answers) Closed 5 years ago . Recently I noticed that using modules was a good option to keep my python programming tidy. For getting started, I made one module (named, oop.py) with a single class in it, which looks like below: #Module named oop class Team: def __init__(self): print "class Team initialized" def displayTeam(self): print "Team name: ", self.name, ",Rank :" , self

PyInstaller cannot find libpython2.7.so when making binary?

限于喜欢 提交于 2020-01-01 05:10:42
问题 I'm trying to make a binary version of a Python script using PyInstaller 2.0 on Linux. When I run: $ python pyinstaller.py myscript.py I get the error: 8907 INFO: Looking for Python library libpython2.7.so Traceback (most recent call last): ... File "pyinstaller.py", line 91, in <module> raise IOError("Python library not found!") IOError: Python library not found! How can this be fixed? I am using: Linux #98-Ubuntu x86_64 GNU/Linux With python 2.7. There are other Pythons on the system but I

pip: inconsistent permissions issues

微笑、不失礼 提交于 2020-01-01 04:20:11
问题 When installing a package via sudo pip-python (CentOS 6 package: python-pip-0.8-1.el6.noarch ), I sometimes get permission issues with the installed packages being readable only by root. Re-installing again one or two times usually fixes the problem. Has anyone experienced this? Or can anyone suggest any troubleshooting steps to nail down the cause? 回答1: When you run a command using sudo , it will preserve the users umask . pip just installs files, it doesn't change access rights, so you'll

What is the reason for using a wildcard import?

[亡魂溺海] 提交于 2019-12-31 07:36:10
问题 I have just learnt about importing modules, and I am a bit confused about the wildcard import. from module_name import * I do not understand the reason of using it at all, I see people saying not to use it at all. Could someone clarify what it really means, and why would one use it? 回答1: According to [Python 3.Docs]: Modules - More on Modules ( emphasis is mine): There is even a variant to import all names that a module defines: >>> from fibo import * >>> fib(500) 0 1 1 2 3 5 8 13 21 34 55 89

Python: “ModuleNotFoundError”, but module is installed?

三世轮回 提交于 2019-12-31 03:12:06
问题 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:\Anaconda3\python.exe) , i.e. I installed Anaconda3 , which includes the matplotlib , and run from PyCharm using the Ananconda3 -interpreter. I've checked in Anaconda Navigator that matplotlib 2.0.2 is installed in the environment. A

Python Modules: When one imports them, do they go into memory?

*爱你&永不变心* 提交于 2019-12-30 17:43:35
问题 I just finished this exercise for beginners on creating and importing modules in python. I was wondering does everything in the module get imported into the computer's memory? Will there be implications later on with memory as the code gets longer and the modules imported become more numerous? Will I need to know memory management to write resource-efficient code because of this? 回答1: Your modules are automatically compiled (.pyc files) which are then imported into memory, but you do not have

ImportError: No module named utils

Deadly 提交于 2019-12-30 17:23:11
问题 I'm trying to import a utilities file but running into a weird error only when I run the code through a script. When I run test.py location: /home/amourav/Python/proj/test.py code: import os os.chdir(r'/home/amourav/Python/') print os.listdir(os.getcwd()) print os.getcwd() from UTILS import * The output is: ['UTILS_local.py','UTILS.py', 'proj', 'UTILS.pyc'] /home/amourav/Python Traceback (most recent call last): File "UNET_2D_AUG17.py", line 11, in from UTILS import * ImportError: No module

ImportError: No module named utils

放肆的年华 提交于 2019-12-30 17:22:57
问题 I'm trying to import a utilities file but running into a weird error only when I run the code through a script. When I run test.py location: /home/amourav/Python/proj/test.py code: import os os.chdir(r'/home/amourav/Python/') print os.listdir(os.getcwd()) print os.getcwd() from UTILS import * The output is: ['UTILS_local.py','UTILS.py', 'proj', 'UTILS.pyc'] /home/amourav/Python Traceback (most recent call last): File "UNET_2D_AUG17.py", line 11, in from UTILS import * ImportError: No module

How can you easily select between PyQt or PySide at runtime?

◇◆丶佛笑我妖孽 提交于 2019-12-30 09:43:31
问题 I would like to do something like this in one source file, QT.py: import sys import PyQt4 sys.modules["Qt"] = PyQt4 Then import this file in the other source files, and use it like this: import QT from Qt.QtCore import * So I can change from PyQt4 to PySide in QT.py without touching all the source files (with a possibly ugly sed script) These modules are mostly API compatibile and I would like to test them both. Is there an easy way to do this? (Because the ways I tried are not working) Maybe

How can you easily select between PyQt or PySide at runtime?

≡放荡痞女 提交于 2019-12-30 09:43:18
问题 I would like to do something like this in one source file, QT.py: import sys import PyQt4 sys.modules["Qt"] = PyQt4 Then import this file in the other source files, and use it like this: import QT from Qt.QtCore import * So I can change from PyQt4 to PySide in QT.py without touching all the source files (with a possibly ugly sed script) These modules are mostly API compatibile and I would like to test them both. Is there an easy way to do this? (Because the ways I tried are not working) Maybe