python-3.4

Python 3 datetime.fromtimestamp fails by 1 microsecond

拟墨画扇 提交于 2019-12-20 01:13:39
问题 I want to save datetimes with microsecond resolution as timestamps. But it seems that Python 3 datetime module lost one microsecond when loading them. To test this let's create a script: test_datetime.py : from random import randint from datetime import datetime now = datetime.now() for n in range(1000): d = datetime(year=now.year, month=now.month, day=now.day, hour=now.hour, minute=now.minute, second=now.second, microsecond=randint(0,999999)) ts = d.timestamp() d2 = datetime.fromtimestamp(ts

Unable to install logging module (Python)

时光毁灭记忆、已成空白 提交于 2019-12-19 17:12:11
问题 I'm trying to install the logging module for Python 3.4. I'm using pip3 install logging. Both times I run into a SyntaxError at line 618 of the init method: "raise NotImplementedError, 'emit must be implemented '\". Someone posted the same question as me, and solved their problem by deleting an interfering third party library called logging: Logging module not working with Python3. But I have no such library already installed in my site-packages directory. Thanks! 回答1: logging is part of the

Hiding the console window after reading input

孤者浪人 提交于 2019-12-19 09:58:46
问题 I have a script that has a GUI, which takes user data and stores it into a text file. It runs another script (an .exe), which waits for user input and then does some work. What I want is for the latter script to hide its console window after reading input from the user, but to continue working in the background. I tried to run that script with subprocess.call('lastscript.exe', shell=True) or subprocess.Popen('lastscript.exe', shell=True) . This doesn't work. I have to take input from the user

How can I adjust pip3 using python3.6 not python3.4 on Ubuntu 14.04?

a 夏天 提交于 2019-12-19 09:07:45
问题 Default python3 on Ubuntu 14.04 is of 3.4.3 but I want to use 3.6.3 instead. I followed commands below to install 3.6.3 : $ sudo apt-get update $ sudo apt-get install build-essential libpq-dev libssl-dev openssl libffi-dev zlib1g-dev $ sudo apt-get install python3-pip python3-dev $ sudo add-apt-repository ppa:jonathonf/python-3.6 $ sudo apt-get update $ sudo apt-get install python3.6 3.6.3 was then available on my Ubuntu: $ which python3.6 /usr/bin/python3.6 For sure, python3 was still

Python doesn't find MagickWand Libraries (despite correct location?)

大憨熊 提交于 2019-12-19 05:49:36
问题 I wanted to install the Python ImageMagick API wand and followed this site: http://docs.wand-py.org/en/latest/guide/install.html#install-imagemagick-on-windows However, when running a very simple test: from wand.image import Image I get the following output: Traceback (most recent call last): File "F:\PATHTO\Python34\lib\site-packages\wand\api.py", line 137, in libraries = load_library() File "F:\PATHTO\Python34\lib\site-packages\wand\api.py", line 107, in load_library raise IOError('cannot

Python doesn't find MagickWand Libraries (despite correct location?)

对着背影说爱祢 提交于 2019-12-19 05:49:09
问题 I wanted to install the Python ImageMagick API wand and followed this site: http://docs.wand-py.org/en/latest/guide/install.html#install-imagemagick-on-windows However, when running a very simple test: from wand.image import Image I get the following output: Traceback (most recent call last): File "F:\PATHTO\Python34\lib\site-packages\wand\api.py", line 137, in libraries = load_library() File "F:\PATHTO\Python34\lib\site-packages\wand\api.py", line 107, in load_library raise IOError('cannot

Python asyncio: reader callback and coroutine communication

依然范特西╮ 提交于 2019-12-18 20:54:12
问题 I am trying to implement a simple idea of passing a data from stdin to a coroutine: import asyncio import sys event = asyncio.Event() def handle_stdin(): data = sys.stdin.readline() event.data = data # NOTE: data assigned to the event object event.set() @asyncio.coroutine def tick(): while 1: print('Tick') yield from asyncio.sleep(1) if event.is_set(): data = event.data # NOTE: data read from the event object print('Data received: {}'.format(data)) event.clear() def main(): loop = asyncio.get

No module named 'openpyxl' - Python 3.4 - Ubuntu

我与影子孤独终老i 提交于 2019-12-18 18:55:09
问题 I installed openpyxl with $ pip install openpyxl when I try the command from openpyxl import Workbook I get Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> from openpyxl import Workbook ImportError: No module named 'openpyxl' I am using Python 3.4 and Ubuntu 14.04, 32-bit OS type 回答1: @zetysz and @Manish already fixed the problem. I am just putting this in an answer for future reference: pip refers to Python 2 as a default in Ubuntu, this means that pip install x

How do I import from a file in the current directory in Python 3?

陌路散爱 提交于 2019-12-18 18:48:33
问题 In python 2 I can create a module like this: parent ->module ->__init__.py (init calls 'from file import ClassName') file.py ->class ClassName(obj) And this works. In python 3 I can do the same thing from the command interpreter and it works (edit: This worked because I was in the same directory running the interpreter). However if I create __ init __.py and do the same thing like this: """__init__.py""" from file import ClassName """file.py""" class ClassName(object): ...etc etc I get

Install django1.7 with Python 3.4 using virtualenv

旧城冷巷雨未停 提交于 2019-12-18 11:30:16
问题 I have hit a bit of a brick wall regarding the set up of django 1.7 using a virtualenv configured to Python 3.4. I have created a Python 3.4 virtualenv using: sudo virtualenv --no-site-packages -p /usr/bin/python3.4 venv I have then activated the env using: source venv/bin/activate Once in the activated virtualenv i have tried: sudo pip install https://www.djangoproject.com/download/1.7b1/tarball/ This installs django in the Python 2.7 directory and not in the virtual environment.. Checking