In Python, if I install a package with pip install package_name
, I can open a Python repl by typing python
and simply import the package by its name, regardless of what directory I'm currently in in the filesystem.
Like so
$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>
and the requests
library is imported and I can play with it in the repl.
In Scala, I know how to do this in a project that uses sbt
, but for learning purposes, I would like to install a package in such a way so that I can simply type scala
at the command line and then import the installed package, without being tied to a specific project.
$ scala
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_40).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scalaz._
<console>:7: error: not found: value scalaz
import scalaz._
How can I do this?
On a Python or JavaScript Repl, you can search for a package to install by clicking on the icon on the sidebar in the workspace. Search for the package you want and select it to install the package or to view its documentation. Clicking on the "Add Package" icon will put it in a spec file and a lock file.
Install it on your system with the following instructions. Download and execute the Scala installer for Windows based on Coursier, and follow the on-screen instructions. JavaScript is disabled, click the tab relevant for your OS. Follow the documentation from Coursier on how to install and run cs setup .
The pip install <package> command always looks for the latest version of the package and installs it. It also searches for dependencies listed in the package metadata and installs them to ensure that the package has all the requirements that it needs.
Description. The Install-Package cmdlet installs one or more software packages on the local computer. If you have multiple software sources, use Get-PackageProvider and Get-PackageSource to display details about your providers.
Scala is different from Python. Code compiled for Scala 2.9.x is not compatible to 2.10.x. So global definitions can cause a lot of problems if you work with different versions.
You can use SBT and add to $HOME/.sbt/plugins/build.sbt
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.4"
or
libraryDependencies += "org.scalaz" % "scalaz-core_2.10" % "7.0.4"
and then go to /tmp and start a Scala REPL with SBT:
sbt console
But on long term it is not a good idea.
The best thing would be to install SBT, create a file build.sbt and put this in it:
libraryDependencies += "org.scalaz" % "scalaz-core_2.10" % "7.0.4"
scalaVersion := "2.10.2"
initialCommands in console := "import scalaz._, Scalaz._"
Now change with the console into the folder of build.sbt and run
sbt console
With this you can experiment with the REPL and have already scalaz imported and in the class path. In addition it is easy to add additional dependencies. SBT is cool, you don't need to install new Scala versions manually, just declare it in build.sbt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With