如何解决点安装火车失败
在虚拟环境中运行@ExtendWith(MockitoExtension.class)
class MaskingPatternLayoutTest {
@Mock
ILoggingEvent event;
@Test
void doLayouttest(){
String patternsproperty = "sensitive string";
String mask = "*";
String logMessage = "message";
// On call of following line in MaskingPatternLayout class,I want to stub the logMessage string
// String logMessage = super.doLayout(event);
// I have tried following approach but Couldn't stub the logMessage string
// ******* Approach - 1 ********
final MaskingPatternLayout maskingPatternLayout = Mockito.spy(new MaskingPatternLayout());
Mockito.doReturn("mocked parent").when((PatternLayout)maskingPatternLayout).doLayout(event);
// with the above approach MaskingPatternLayout class doLayout() method will not execute,instead
// it returns logMessage string but I wanted to stub on calling "super.doLayout(event)"
// ******* Approach - 2 ********
//when(layout.doLayout(event)).thenReturn(logMessage);
// Above statement will not work because of calling "doLayout(event)" using super keyword
// ******* Approach - 3 ********
// PatternLayout super class provides another protected method "writeLoopOnConverters(event)"
// which provide same return value of "super.doLayout(event)" So,I have tried as fallows
// First I have done spy on "PatternLayout layout = spy(PatternLayout.class);" and added the
// following statement.
Mockito.doReturn("mocked parent").when((PatternLayout)maskingPatternLayout).doLayout(event);
// But above line will skip calling "doLayout(ILoggingEvent event)" method of
// "MaskingPatternLayout" class
String maskedLog = maskingPatternLayout.doLayout(event);
assertNotNull(maskedLog );
}
}
后
我得到了
pip install trains
我知道I am not supposed to run under sudo when using a venv,所以我不太了解这个问题
例如运行 ERROR: Command errored out with exit status 1:
command: /home/epdadmin/noam/code/venv_linux/bin/python -u -c 'import sys,setuptools,tokenize; sys.argv[0] = '"'"'/tmp/pip-install-owzh8lnl/retrying/setup.py'"'"'; __file__='"'"'/tmp/pip-install-owzh8lnl/retrying/setup.py'"'"';f=getattr(tokenize,'"'"'open'"'"',open)(__file__);code=f.read().replace('"'"'\r\n'"'"','"'"'\n'"'"');f.close();exec(compile(code,__file__,'"'"'exec'"'"'))' install --record /tmp/pip-record-lxz5t8pu/install-record.txt --single-version-externally-managed --compile --install-headers /home/epdadmin/noam/code/venv_linux/include/site/python3.8/retrying
cwd: /tmp/pip-install-owzh8lnl/retrying/
Complete output (10 lines):
running install
running build
running build_py
creating build
creating build/lib
copying retrying.py -> build/lib
running install_lib
copying build/lib/retrying.py -> /home/epdadmin/noam/code/venv_linux/lib/python3.8/site-packages
byte-compiling /home/epdadmin/noam/code/venv_linux/lib/python3.8/site-packages/retrying.py to retrying.cpython-38.pyc
error: [Errno 13] Permission denied: '/home/epdadmin/noam/code/venv_linux/lib/python3.8/site-packages/__pycache__/retrying.cpython-38.pyc.139678407381360'
----------------------------------------
ERROR: Command errored out with exit status 1: /home/epdadmin/noam/code/venv_linux/bin/python -u -c 'import sys,'"'"'exec'"'"'))' install --record /tmp/pip-record-lxz5t8pu/install-record.txt --single-version-externally-managed --compile --install-headers /home/epdadmin/noam/code/venv_linux/include/site/python3.8/retrying Check the logs for full command output.
确实可以。
Python 3.8
如何安装火车?
编辑:
运行pip install pandas
或pip install trains --user
给出
pip install --user trains
解决方法
您有两个选择:
-
创建一个虚拟环境并在其中安装软件包(首选)
-
通过传递--user标志,将软件包安装在用户主目录中
pip install --user
问题是venv的权限问题。 另一个问题是火车需要一些软件包,而这些软件包在Python3.8上还没有带轮子,因此我不得不将Python降级到3.7
该venv是使用Pycharm创建的,由于某种原因,它是使用低权限创建的。
可能有一种提高权限的方法,但是我只是删除了它,并使用命令行创建了另一个方法,
python -m virtualenv --python=/usr/bin/python3.7 venv
现在pip install trains
工作了。
非常烦人。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。