我刚刚在我的Windows机器上安装了PyCharm。运行Python 2.7.10,我有一个带
行的模块import paho.mqtt.client as client
我得到了没有名为paho'的模块。错误。我在主机上的Python27安装上安装了pip和paho,但是PyCharm还没有找到它。
如何将paho库导入PyCharm?
答案 0 :(得分:0)
我在这里找到了答案:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Parallels.Tests
{
[TestClass]
public class GetterTests
{
//this test always succeeds
[TestMethod]
public void ResultTest()
{
for (var i = 0; i < 500; i++)
{
var currentThreadId = Thread.CurrentThread.ManagedThreadId;
var instantThreadId = ThreadGetter.GetThreadIdInstant().Result;
var delayedThreadId = ThreadGetter.GetThreadIdDelayed().Result;
var forcedNewThreadId = ThreadGetter.GetThreadIdForcedNew().Result;
Assert.AreEqual(currentThreadId, instantThreadId);
Assert.AreNotEqual(currentThreadId, delayedThreadId);
Assert.AreNotEqual(currentThreadId, forcedNewThreadId);
}
}
//mixed results
[TestMethod]
public async Task AwaitDelayedTest()
{
for (var i = 0; i < 500; i++)
{
try
{
var currentThreadId = Thread.CurrentThread.ManagedThreadId;
var delayedThreadId = await ThreadGetter.GetThreadIdDelayed();
Assert.AreNotEqual(currentThreadId, delayedThreadId);
}
catch (Exception ex)
{
throw new Exception($"failed at iteration: {i}", ex);
}
}
}
//mixed results
[TestMethod]
public async Task AwaitForcedNewTest()
{
for (var i = 0; i < 500; i++)
{
try
{
var currentThreadId = Thread.CurrentThread.ManagedThreadId;
var forcedNewThreadId = await ThreadGetter.GetThreadIdForcedNew();
Assert.AreNotEqual(currentThreadId, forcedNewThreadId);
}
catch (Exception ex)
{
throw new Exception($"failed at iteration: {i}", ex);
}
}
}
}
public static class ThreadGetter
{
public static async Task<int> GetThreadIdInstant() => Thread.CurrentThread.ManagedThreadId;
public static async Task<int> GetThreadIdDelayed()
{
await Task.Delay(1);
return Thread.CurrentThread.ManagedThreadId;
}
public static async Task<int> GetThreadIdForcedNew() => await Task.Run(() => Thread.CurrentThread.ManagedThreadId);
}
}
文件:设置:项目:项目翻译,单击右上角的“+”,滚动到paho.mqtt,选择并单击“安装包”
再好不过了 - 谢谢大家。