小编Iva*_*kov的帖子

Python"pip install"因AttributeError而失败:'module'对象没有属性'SSL_ST_INIT'

$ sudo pip install --upgrade pyOpenSSL

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==8.1.1', 'console_scripts', 'pip')()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 558, 
in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 
2682, in load_entry_point
return ep.load()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 
2355, in load
return self.resolve()
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 
2361, in resolve
 module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
 py2.7.egg/pip/__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar  # noqa
 File "/usr/local/lib/python2.7/dist-packages/pip-8.1.1-
 py2.7.egg/pip/vcs/mercurial.py", line 9, in <module>
from …
Run Code Online (Sandbox Code Playgroud)

python ubuntu pyopenssl python-2.7

58
推荐指数
2
解决办法
4万
查看次数

"使用"pip install virtualenv"时无法找到'pip._vendor.distlib'的查找器"错误

我试图在Windows 10下使用Python 3.6版本安装virtualenv.当我运行"pip install virtualenv"时,我收到此错误.我是Python的新手.

Collecting virtualenv
  Downloading virtualenv-15.0.3-py2.py3-none-any.whl (3.5MB)
    100% |????????????????????????????????| 3.5MB 256kB/s
Installing collected packages: virtualenv
Exception:
Traceback (most recent call last):
  File "c:\users\corey shaw\appdata\local\programs\python\python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\users\corey shaw\appdata\local\programs\python\python36\lib\site-packages\pip\commands\install.py", line 317, in run
    prefix=options.prefix_path,
  File "c:\users\corey shaw\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_set.py", line 742, in install
    **kwargs
  File "c:\users\corey shaw\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_install.py", line 831, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "c:\users\corey shaw\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_install.py", line 1032, in move_wheel_files
    isolated=self.isolated,
  File "c:\users\corey shaw\appdata\local\programs\python\python36\lib\site-packages\pip\wheel.py", line 493, in move_wheel_files
    maker.make_multiple(['%s = %s' % …
Run Code Online (Sandbox Code Playgroud)

python pip virtualenv python-3.x

16
推荐指数
4
解决办法
6530
查看次数

基于PHP的基于HTTP的录制文件实时视频流

我想基于PHP组织基于HTTP的录制文件的实时流式传输.

简介:在流媒体服务器上,我将视频写入本地文件(local_file.mpg),当收到来自客户端的请求,然后从
$start_byte = filesize("local_file.mpg")-10MB; local_file.mpg 开始流式传输,仍在编写,PHP脚本继续读取并刷新.

问题:我通过HTTP Range使用以下标头进行流式传输:

header('HTTP/1.1 206 Partial Content');
header("Content-Type: video/mpeg");
header('Content-Length: '.($seek_end - $seek_start));
header('Content-Range: bytes '.$seek_start.'-'.$seek_end.'/'.$size);
Run Code Online (Sandbox Code Playgroud)

冲洗如下:

while(!feof($fp)){
    $buf_size = 1024*8;
    $pos = ftell($fp);
    if ($pos >= $item["to_byte"]){
            fclose($fp);
            break;
    }

    if ($pos + $buf_size > $item["to_byte"]){
        $buf_size = $item["to_byte"] - $pos;
    }

    if ($buf_size > 0){
        echo fread($fp, $buf_size);
    }

    flush();
    ob_flush();
}
Run Code Online (Sandbox Code Playgroud)

我通过VLC或FFplay打开它,但它一直播放到请求流的时刻.这是预料之中的,因为我们确定文件的大小并将其提供给请求方.但是,如果我们人为地增加文件大小,例如
$size = filesize("local_file.mpg")+999999999999;它也没有帮助,因为视频播放器在没有记录时过早地请求新数据.并且在请求流的时刻也停止播放.

1.请建议如何根据PHP纠正通过HTTP记录文件组织实时流式传输.
2.是否可以使用HTTP RANGE机制进行,或者我应该使用其他方式?


更新:基于这个问题,我尝试了下一个代码:

<?php

$file = "online.mpg";

function flush_buffers(){ …
Run Code Online (Sandbox Code Playgroud)

php streaming http vlc video-streaming

13
推荐指数
1
解决办法
1148
查看次数

CeleryBeat Process消耗所有操作系统内存

我们正在使用

django-celery==3.1.10
celery==3.1.20
python 2.7.13
Run Code Online (Sandbox Code Playgroud)

我们编写了一个CustomDataBaseScheduler来安排任务,它可以按时完美地安排任务.我们将CeleryBeat Process作为init脚本运行,但celeryBeat消耗系统的全内存,即一天24GB.

我试图在celerybeat Process上运行pmap,但它显示[anon]占用了大部分内存.

有人可以帮助调试和解决这个问题.

python celery python-2.7 django-celery

11
推荐指数
1
解决办法
523
查看次数

在tkinter ttk treeview中格式化单个单元格/项目而不是整行

我目前正在使用函数以电子表格样式格式显示pandas数据框.我希望能够根据其内容添加一些功能来格式化树视图的单个单元格,例如,如果它们包含子串"X"或者它们的值高于Y.

目前实施的更新功能如下:

   def updateTree(self, dataframe):
    '''
    Updates the treeview with the data in the dataframe
    parameter
    '''
    #Remove any nan values which may have appeared in the dataframe parameter
    df = dataframe.replace(np.nan,'', regex=True)

    #Currently displayed data
    self.treesubsetdata = dataframe

    #Remove existing items
    for item in self.tree.get_children(): self.tree.delete(item)
    #Recreate from scratch the columns based on the passed dataframe
    self.tree.config(columns= [])
    self.tree.config(columns= list(dataframe.columns))

    #Ensure all columns are considered strings and write column headers
    for col in dataframe.columns:
        self.tree.heading(col,text=str(col))

    #Get number of rows …
Run Code Online (Sandbox Code Playgroud)

python treeview tkinter ttk python-3.x

8
推荐指数
1
解决办法
767
查看次数

在Django ORM中,"值"和"注释"不适用于分组

我有这样一张桌子:

在此输入图像描述

现在我想总结每个日期的饭菜.我写了下面的代码.但它并不像我想的那样有效.

模型:

class Meal(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
    date_of_meal = models.DateField()
    morning_meal = models.SmallIntegerField(default=0)
    mid_day_meal = models.SmallIntegerField(default=0)
    night_meal = models.SmallIntegerField(default=0)
    updated = models.DateTimeField(auto_now=True, auto_now_add=False)
    timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)

    class Meta:
        ordering = ['-updated', '-timestamp']

    def __str__(self):
        return str(self.date_of_meal)
Run Code Online (Sandbox Code Playgroud)

码:

meals_list = Meal.objects.values('date_of_meal').annotate(mm=Sum('morning_meal'), mdm=Sum('mid_day_meal'), nm=Sum('night_meal'))
Run Code Online (Sandbox Code Playgroud)

输出:

<QuerySet [{'mdm': 0, 'mm': 1, 'date_of_meal': datetime.date(2017, 3, 
23), 'nm':
 1}, {'mdm': 1, 'mm': 1, 'date_of_meal': datetime.date(2017, 3, 23), 'nm': 0}, {
'mdm': 1, 'mm': 0, 'date_of_meal': datetime.date(2017, 3, 22), 'nm': 1}, {'mdm':
 0, …
Run Code Online (Sandbox Code Playgroud)

python django django-orm python-3.x

8
推荐指数
1
解决办法
2028
查看次数

使用ffmpeg编码AAC(c ++)

我正在研究将在Unity插件中使用的视频编码.我已经使图像编码工作,但现在我在音频.所以只尝试将音频输入到具有AAC编码的mp4文件中.而且我被困住了.生成的文件不包含任何内容.另外,根据我的理解,ffmpeg中的AAC仅支持AV_SAMPLE_FMT_FLTP,这就是我使用它的原因.这是我的代码:

建立:

int initialize_encoding_audio(const char *filename)
{
    int ret;
    AVCodecID aud_codec_id = AV_CODEC_ID_AAC;
    AVSampleFormat sample_fmt = AV_SAMPLE_FMT_FLTP;

    avcodec_register_all();
    av_register_all();

    aud_codec = avcodec_find_encoder(aud_codec_id);
    avcodec_register(aud_codec);

    if (!aud_codec)
        return COULD_NOT_FIND_AUD_CODEC;

    aud_codec_context = avcodec_alloc_context3(aud_codec);
    if (!aud_codec_context)
        return CONTEXT_CREATION_ERROR;

    aud_codec_context->bit_rate = 192000;
    aud_codec_context->sample_rate = select_sample_rate(aud_codec);
    aud_codec_context->sample_fmt = sample_fmt;
    aud_codec_context->channel_layout = AV_CH_LAYOUT_STEREO;
    aud_codec_context->channels = av_get_channel_layout_nb_channels(aud_codec_context->channel_layout);

    aud_codec_context->codec = aud_codec;
    aud_codec_context->codec_id = aud_codec_id;

    ret = avcodec_open2(aud_codec_context, aud_codec, NULL);

    if (ret < 0)
        return COULD_NOT_OPEN_AUD_CODEC;

    outctx = avformat_alloc_context();
    ret = avformat_alloc_output_context2(&outctx, NULL, "mp4", filename);

    outctx->audio_codec = aud_codec;
    outctx->audio_codec_id = …
Run Code Online (Sandbox Code Playgroud)

c++ ffmpeg aac video-encoding

7
推荐指数
1
解决办法
2225
查看次数

Pytest - 使用 asyncio 进行 python 测试

是否可以event loop从函数返回执行。并尽快Task完成返回函数并继续执行?

我正在尝试使用pytest-asyncio插件

例子:

@pytest.mark.asyncio
async def test_async1(event_loop):
    print('start 1')
    res = event_loop.create_task(
        send_async_request("http://test.com", limit=1000))) # here I need to return execution to event loop and continue only after getting response from send_async_request function 
    print('end1',res)



@pytest.mark.asyncio
async def test_async2(event_loop):
    print('start 2')
    res = event_loop.create_task(
        send_async_request("http://test2", limit=1000))) # here I need to return execution to event loop and continue only after getting response from send_async_request function
    print('end2', res)
Run Code Online (Sandbox Code Playgroud)

send_async_request- aiohttp

@asyncio.coroutine
def send_async_request(url, …
Run Code Online (Sandbox Code Playgroud)

python pytest python-3.x python-asyncio

7
推荐指数
1
解决办法
7922
查看次数

如何在GDB/clion2017.1中将python包安装到嵌入式python中

我正在使用CLion 2017.1和GDB进行调试.GDB使用python 2.7支持编译,但没有模块.

我想用matplotlib它来绘制一些调试数据(使用GDB图像监视),但没有matplotlib存在.并且不pip安装它.

我试过安装pip使用(gdb) python import get_pip但是

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/temp/get_pip.py", line 28, in     <module>
    import tempfile
  File "/home/user/clion-2016.3.4/bin/gdb/lib/python2.7/tempfile.py", line 35, in <module>
    from random import Random as _Random
  File "/home/user/clion-2016.3.4/bin/gdb/lib/python2.7/random.py", line 48, in <module>
    from binascii import hexlify as _hexlify
ImportError: No module named binascii
Error while executing Python code.
Run Code Online (Sandbox Code Playgroud)

所以我不知道如何将其他模块的安装引导到GDB的嵌入式python中.

知道怎么做吗?

python gdb pip python-2.7 clion

6
推荐指数
1
解决办法
1235
查看次数

如何在Python上使用异常时使用带有Selenium Webdriver的try/except

我正在尝试使用try/except语句来查找WebDrive中是否存在元素,如果是,则运行特定的代码行,

try:
    WebDriver.find_element_by_css_selector('div[class="..."')
except NoSuchElement:
    ActionToRunInCaseNoSuchElementTrue
else:
    ActionToRunInCaseNoSuchElementFalse
Run Code Online (Sandbox Code Playgroud)

但运行此代码会出错:

  • NameError:未定义名称"NoSuchElement"

如何定义异常?是否有更短/更简单的方法来检查网页中是否存在元素并且如果是,则运行命令,否则运行另一个元素?

python selenium python-3.x selenium-webdriver

6
推荐指数
1
解决办法
5629
查看次数