I know how to run rascal code from within eclipse and how to use the REPL, but I don't know how I can run a rascal file (or group of rascal files) as a program from the command line.
When I try the following, I get a parse error:
$ java -Xmx1G -Xss32m -jar rascal-shell-stable.jar mymodule.rsc
Version: 0.7.2.201501130937
Parse error in cwd:///mymodule.rsc from <1,11> to <1,12>
The contents of mymodule.rsc:
module mymodule
println("hello world");
What am I doing wrong?
Well, your mymodule.rsc is actually syntactically incorrect and will also give parse errors in the Eclipse IDE. Here is an improved version:
module mymodule
import IO;
value main(list[value] args) {
println("hello world");
}
Bonus: you should also add import IO; to make the println function available.
Related
I have a problem. When writing the "pip install pyowm" command to the console, the module is installed, but the system doesn't see it. For example, Phyton, when executing the command "impor pyowm", gives an error, and when writing the command "pyowm" to the console, the error "" pyowm " is not an external or internal command".
All of the above apply to other modules as well.
P.S. I use VS Code and Python v.3.8.3
From https://github.com/csparpa/pyowm:
from pyowm import OWM
The package name (pyowm) and the module name (OWM) do not necessarily need to correspond.
You can't just use any tool just by name from the console.
You have to first enter python to the console and then try import pyowm again.
It should import pyowm. But later you may want to actually use pyowm. Then you use this import most of the time:
from pyowm.owm import OWM
I want to run python script in Scala program, I ran the python script in spark-shell, but same code I tried in Scala IDE it throws "No such file or directory".
My code in spark-shell:-
python file : a.py
scala script:-
file="a.py"
Seq("python",file) !
Above code ran successfully in spark-shell and I tried same code in Scala IDE
object newtest {
def runpython(file:String)={
Seq("python",file) !
}
def main(args: Array[String]):Unit={
val file="/sample/a.py"
runpython(file)
}
}
note:- "/sample" is project folder in scala IDE
Please help me on this.
Thanks,
Prasad.
I would guess that the missing file is python.
try setting the full path of the python executable
I've recently installed Scala as a part of my functional programming course and I've encountered a problem: IntelliJ IDEA 2017.2.1 (Java version 9, build 9+181) doesn't run any of my scala code, exitting with
Error: Could not find or load main class Main
This code is an example.
object Main {
def length[A](list:List[A]):Int = {
if (list == Nil) 0
else 1 + length(list.tail)
}
def main(args: Array[String]): Unit = {
length(List[Int](1, 4, 5, 12, -1))
}
}
It's really simple, yet IntelliJ refuses to run it. Windows CMD doesn't even react to a scala command, resulting into
'scala' is not recognized as an internal or external command,
operable program or batch file.
even though I have it installed on my computer. If I call Scala Console inside of IntelliJ everything works fine and compiles as expected. I've tried switching to JDK 1.8 inside of IntelliJ, yet it led to no result.
What could be the problem?
For me it turns out that the src/main was not marked as Sources Root
which causes the following error
...
One of the two will be used. Which one is undefined.
Error: Could not find or load main class Main
Process finished with exit code 1
So of course after I mark the src/main as Sources Root, the Scala Hello World example runs happy again.
Notice the blue color of directory src/main when it's marked as Sources Root
Are you using the little green arrow to run the program from inside of your Main object?
How did you create the program? It could be that your build file SBT configuration of the project is a different Scala version than what's installed on your computer.
It's really simple, yet IntelliJ refuses to run it. Windows CMD
doesn't even react to a scala command, resulting into
'scala' is not recognized as an internal or external command, operable program or batch file.
This means that Scala is not added to your class path in your terminal. Look up how to do that and see if that doesn't help out your IntelliJ problem too.
I'm trying to write some plugins for the irc bot supybot with eclipse/pydev. Pydev gives me errors about unresolved imports on supybot-modules/packages (e. g. import supybot.utils as utils), but works ok on e. g. "from supybot.commands import *". So I guess I set up dydev correctly, as it finds the wanted modules. The problem must be in pydev/eclipse, as the bot works correct and in eric5 I get also no errors about that.
Removing the interpreter and setting it up didn't help. Any other ideas on how to fix this? System: Arch Linux, Eclipse Juno, PyDev 2.7.1, wanted (and set up) python interpreter is 2.7, supybot is installed in site-packages for Python 2.7.
Edit: Just noticed: PyDev doesn't mark the "from ... import *" as error, but if I use functions imported from there I get an error on that function.
Code sample:
[...]
import supybot.utils as utils
from supybot.commands import *
[...]
wunsch = wrap(wunsch, ['text', 'now'])
[...]
Error on the first line: Unresolved import: utils
Second line gets no error nor warning
Error on 3rd line: Undefined variable: wrap
But 'wrap' is a function declared in supybot.commands
Run import supybot; print supybot.__path__ to get the path to the supybot package. PyDev may be importing the wrong one (for example if you use a folder called supybot in your workspace).
import org.apache.tools.ant.Project
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
I tried to run this code using following command:
java -cp D:\tools\apache-ant-1.7.0\lib\ant.jar;D:\tools\scala-2.9.1.final\lib\scala-compiler.jar;D:\tools\scala-2.9.1.final\lib\scala-library.jar -Dscala.usejavacp=true scala.tools.nsc.MainGenericRunner D:\test\scala\ant.scala
There is following error:
D:\test\scala\ant.scala:1: error: object apache is not a member of package org
import org.apache.tools.ant.Project
^
one error found
What is wrong?
UPDATE:
As I can see it is impossible to import any org.xxx package.
The same problem with javax.xml.xxx package.
D:\test\test2.scala:2: error: object crypto is not a member of package javax.xml
import javax.xml.crypto.Data
^
one error found
Actually I cannot import anything!
D:\test\test3.scala:3: error: object test is not a member of package com
import com.test.utils.ant.taskdefs.SqlExt
^
one error found
You haven't included the ant jar file in your classpath.
The compiler effectively builds objects representing the nested package structure. There is already a top-level package named org from the JDK (org.xml for example) but without additional jars org.apache is not there.
I found that in general when an error of type Object XXX is not a member of package YYY occurs, you should:
Check that all your files are in a package, ie. not in the top-level src/ directory
I experimented with scala.bat (uncommenting the echo of the final command line, see the line starting with echo "%_JAVACMD%" ...) and found that this should work:
java -Dscala.usejavacp=true -cp d:\Dev\scala-2.9.1.final\lib\scala-compiler.jar;d:\Dev\scala-2.9.1.final\lib\scala-library.jar scala.tools.nsc.MainGenericRunner -cp d:\Dev\apache-ant-1.8.2\lib\ant.jar D:\test\scala\ant.scala
I would check that 'D:\tools\apache-ant-1.7.0\lib\ant.jar' exist and also check that it is not corrupt (length 0 or unable to open with 'jar tf D:\tools\apache-ant-1.7.0\lib\ant.jar').
Run with scala command instead:
scala -cp D:\tools\apache-ant-1.7.0\lib\ant.jar;D:\tools\scala-2.9.1.final\lib\scala-compiler.jar;D:\tools\scala-2.9.1.final\lib\scala-library.jar D:\test\scala\ant.scala