简体   繁体   English

在python中,如何向bash_profile添加命令?

[英]In python, how to add command to bash_profile?

My enviroment is Google Colab, which is in Python. 我的环境是Google Colab,它是用Python编写的。 I am trying to follow the instructions on this website. 我正在尝试按照本网站上的说明进行操作。

https://github.com/abisee/cnn-dailymail https://github.com/abisee/cnn-dailymail

And it mentions to 它提到了

Then add the following command to your bash_profile: 然后将以下命令添加到bash_profile:

export CLASSPATH=/path/to/stanford-corenlp-full-2017-06-09/stanford-corenlp-3.8.0.jar

My best guess was to run using 我最好的猜测就是继续使用

!export CLASSPATH=/stanford-corenlp-full-2017-06-09/stanford-corenlp-3.8.0.jar !export CLASSPATH = / stanford-corenlp-full-2017-06-09 / stanford-corenlp-3.8.0.jar

Which executed without any errors 哪个执行没有任何错误

But then the instructions say to 但随后说明说

You can check if it's working by running 您可以通过运行检查它是否正常工作

echo "Please tokenize this text." | java edu.stanford.nlp.process.PTBTokenizer

So I tried 所以我试过了

!echo "Please tokenize this text." | java edu.stanford.nlp.process.PTBTokenizer

But then I got this error 但后来我得到了这个错误

Error: Could not find or load main class edu.stanford.nlp.process.PTBTokenizer
Caused by: java.lang.ClassNotFoundException: edu.stanford.nlp.process.PTBTokenizer

Edit: 编辑:

I found instructions to install Java in colab 我找到了在colab中安装Java的说明

# Install Java
!apt-get install -y openjdk-8-jdk-headless -qq > /dev/null
os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-8-openjdk-amd64"
!java -version

But

!echo "Please tokenize this text." | java edu.stanford.nlp.process.PTBTokenizer

Still gives the same error 仍然给出相同的错误

I'd recommend not changing your .bash_profile as you're going to accumulate settings and junk. 我建议不要更改你的.bash_profile因为你要累积设置和垃圾。

Instead, java lets you specify CLASSPATH with the -cp option, which we can add to the Python script. 相反,java允许您使用-cp选项指定CLASSPATH,我们可以将其添加到Python脚本中。

(You can also use java -cp /path/to/blahblah.jar etc to test it as their instructions recommend.) (您也可以使用java -cp /path/to/blahblah.jar etc按照他们的说明进行测试。)

Change this line in make_datafile.py to: make_datafile.py中的这一行更改为:

command = ['java', '-cp', '/path/to/blahblah.jar', 'edu.stanford.nlp.process.PTBTokenizer', 
           '-ioFileList', '-preserveLines', 'mapping.txt']

If you're still having trouble, make sure you have a valid jar! 如果您仍然遇到问题,请确保您有一个有效的罐子!

List the contents with: 列出内容:

jar -tvf /path/to/blahblah.jar

You should see edu/stanford/nlp/process/PTBTokenizer.class listed, otherwise no amount of messing with the CLASSPATH will fix it. 你应该看到列出了edu/stanford/nlp/process/PTBTokenizer.class ,否则没有任何搞乱CLASSPATH的东西会修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM