Claudio Ferreira
Claudio Ferreira

Reputation: 45

Problems while creating a deps.edn file

People, I decided to rewrite this post entirely to show it in a clear way.

First of all, thanks for all the support. I appreciate that.

This is the exercise in "The Clojure Workshop - Packt" where i've got stuck:

(My IDE is IntelliJ and i'm using Windows).

Exercise 4.10: Importing Data from a CSV File

1. Create a folder somewhere convenient on your computer.

I decided to create an entirely new project.

Is there any difference here while choosing between Leiningen or Deps? I most of the time use Leiningen, but should i use Deps because i am gonna use a deps.edn file?

2. Download the match_scores_1991-2016_UNINDEXED.csv file to the folder you created. (here on github)

But where should i download this file? Into the src file inside the project file or any file works? Is there any difference?

I decided to save inside de src.

3. In your editor, in the same folder, create a deps.edn file with the following contents:

{:deps
 {org.clojure/data.csv {:mvn/version "0.1.4"}
  semantic-csv {:mvn/version "0.2.1-alpha1"}}}

So, i created a deps.edn file.

4. Verify that everything is working by evaluating the following expression in your REPL:

user> (require '[clojure.data.csv :as csv])
nil
user> (require '[clojure.java.io :as io])
nil
user> (with-open [r (io/reader "match_scores_1991-2016_unindexed_csv.csv")]
         (first (csv/read-csv r)))

Created a new local Clojure REPL for this project.

But when i am gonna evaluate the testing expressions, it shows an error while evaluating the second one and third one.

As you can see here.

The error while evaluating the "clojure.data.csv :as csv" is this one:

Execution error (FileNotFoundException) at csv-example.core/eval1549 (form-init2604783929697477049.clj:1).
Could not locate clojure/data/csv__init.class, clojure/data/csv.clj or clojure/data/csv.cljc on classpath.

What am i missing? Have been trying for days to solve this but i didn't found any answer.

Thank you!

Upvotes: 2

Views: 1698

Answers (2)

Claudio Ferreira
Claudio Ferreira

Reputation: 45

You can solve the problem by doing what Sean Corfield commented on the post if you choose to use deps.edn.

Or, if you prefer leiningen you can solve that just by adding


[org.clojure/data.csv   "1.0.0"]
[semantic-csv           "0.2.1-alpha1"]

at the :dependencies key inside the project.clj file.

inside the project.clj file.

Upvotes: 2

Sean Corfield
Sean Corfield

Reputation: 6666

I'll try to answer all the questions here and get you to the next stage:

  1. Leiningen uses a project.clj file. The Clojure CLI uses a deps.edn file. Since the book is asking you to create a deps.edn file, you'll need to use the Clojure CLI, not Leiningen, to start a REPL and/or run the code. More on this below.

  2. The book expects you to download the .csv file to whichever folder you created in step 1. The folder that contains your deps.edn file. Looking at your screenshots, it looks like you asked Cursive/IntelliJ to create a Leiningen-based project. If you start again and ask Cursive/IntelliJ to create a Deps-based project, you'll have a deps.edn file at the top of the project, which you can edit to look like what the book wants, and you'll end up with:

  • deps.edn
  • match_scores_1991-2016_unindexed.csv
  • src

(and maybe some other files that Cursive/IJ might create)

  1. Per my comments in 2. above, you'll have a deps.edn file -- created by Cursive/IJ -- that you can edit, in the top of the project.

  2. The error you got was because you created a Leiningen project, and then started a Leiningen REPL -- and it doesn't know about deps.edn so it won't see what you added there (even if you'd put it in the top of the project, next to project.clj). So Leiningen didn't know you wanted the CSV library and therefore it wasn't available in the REPL when you tried to require it -- and because the require failed, you didn't get the csv alias and so the call to csv/read-csv failed to compile.

Two points about the Clojure CLI:

a. It's substantially simpler to use than Leiningen and requires much less structure in a project. You could create a Deps-based project manually at the command line. Open a Command Prompt (cmd.exe) and you can do the following:

C:\Users\seanc>mkdir myproject

C:\Users\seanc>cd myproject

C:\Users\seanc\myproject>notepad deps.edn

C:\Users\seanc\myproject>dir
 Volume in drive C is Local Disk
 Volume Serial Number is 4459-1FFE

 Directory of C:\Users\seanc\myproject

01/05/2021  02:24 PM    <DIR>          .
01/05/2021  02:24 PM    <DIR>          ..
01/05/2021  02:25 PM               101 deps.edn
               1 File(s)            101 bytes
               2 Dir(s)  158,998,511,616 bytes free

(then you could download the .csv file into myproject and then start the REPL the way the book probably shows you -- I expect it suggests you run the clj command in that folder)

b. And here's where you run into a problem: Windows is not very well-supported by a lot of tools and libraries in the Clojure world -- nearly all Clojure developers either use Macs or Linux. Even those who use Windows generally use WSL2 (on Windows 10) and a Linux flavor such as Ubuntu. Because that's easier than trying to work with the tools on Windows.

There is a prerelease version of the Clojure CLI available for Powershell on Windows: https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows

As noted at the bottom of that page, it's easier to install Scoop and then use that to install the Clojure CLI. And then use Powershell instead of the Command Prompt.

I don't know how you feel about WSL2/Linux or Powershell -- since you're new to programming, I suspect that's all going to seem somewhat complex and rather daunting. What you might consider is abandoning "The Clojure Workshop" (Packt books are generally not very good anyway) and find either another book or an online tutorial that takes you through using Leiningen (preferably on Windows -- but that might be hard to find, since so few Clojurians use Windows) and to try to work through that material with Cursive/IJ.

Upvotes: 2

Related Questions