I have recently started learning haskell and have never used the cabal package manager before. I'm currently working on a project that requires me to user the io-streams package.
I of course already have the Haskell Platform installed on my machine. I am currently using the x86_64-core version 8.4.3 installer.
Using a Git Bash terminal on Windows 10, I have created a .cabal-sandbox/ folder (using the cabal sandbox init command), in which to house all of my downloaded packages. I have then run cabal install io-streams to download and install the package from the Hackage site. This has worked fine.
I have now come to writing my code. This is as follows:
module StreamFiles where
import System.IO.Streams.File
main:: IO ()
main = do
putStrLn "some text here"
However, when I come to run this, using the following steps:
1. Run the cabal repl command in the directory where the .cabal-sandbox/ folder is located.
2. I then run the following in Powershell:
Prelude> :l src/fileStreaming/streamfile.hs
[1 of 1] Compiling StreamFile ( src\fileStreaming\streamfile.hs, interpreted )
Ok, one module loaded.
*StreamFile> main
And get the following error:
ghc.exe: | C:\Users\UserName\source\repos\complexHaskell\.cabal-sandbox\x86_64-windows-ghc-8.4.3\network-3.0.1.0-HkosMKsQUp05NPIgp4K8kv\HSnetwork-3.0.1.0-HkosMKsQUp05NPIgp4K8kv.o: unknown symbol `if_nametoindex'
ghc.exe: unable to load package `network-3.0.1.0'
And I cannot work out why. Is this a package problem or is there a step that I have missed when pulling the packages down from the Hackage site?
Do I need to create a .cabal file using the cabal init command and require some dependencies for my imports in there??
Thanks in advance.
C.
Related
I'm a newbie on Golang, and I'm trying to use Gin to develop a web server on Ubuntu 16.04.
After executing go get -u github.com/gin-gonic/gin, many folders appear at ~/go/pkg/mod/github.com/.
Then I try to make an example:
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
However, go run example.go made the error:
example.go:3:8: cannot find package "github.com/gin-gonic/gin" in any of:
/usr/local/go/src/github.com/gin-gonic/gin (from $GOROOT)
/home/zyh/go/src/github.com/gin-gonic/gin (from $GOPATH)
In my system, $GOROOT is /usr/local/go/ and $GOPATH is ~/go/.
How could I solve this problem?
For Go version 1.11 or newer, You should use Go Modules.
If you are just starting with Go, you should start with the newer version. I think you are using a Go version that supports go modules already because the modules you are trying to get are downloading to ~/go/pkg/mod/ directory.
To initialize a project with go module, run:
go mod init your-project-name
This will create a go.mod file in your project directory.
Add missing and/or remove unused modules:
go mod tidy
This will fill up the go.mod file with appropriate modules and create a go.sum in your project directory. The go.sum contains expected cryptographic hashes of each module version.
After that, the go run example.go command should run the program without any issues.
You can even vendor the modules in your project directory:
go mod vendor
This will bring all the vendors to your projects /vendor directory so that you don't need to get the modules again if working from another machine on this project.
I realized that after adding a package called gopls, my IDE is working perfectly.
Install gopls using snap: sudo snap install gopls --classic
From the error, you can see that GOPATH is your '/home/zyh/go' not your ~/go.
and you can run shell go env to confirm where is your GOPATH? then modify it.
Hi I use GHCI and can normally load my files. Now I need to load a file that uses random. I get this error.
Chatterbot.hs:3:1: error:
Could not find module ‘System.Random’
Use -v to see a list of the files searched for.
|
3 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
This is very weird since it works for my friend who also have just installed GHCI and did nothing other than me. The main difference is that I am on windows. I really don t understand this and have tried googling a bit and many people speak about stack but it seems annoying and It obviously works for my friend without it.
Thanks in advance
EDIT problem solved. I needed to update cabal then I ran cabal install random and it worked well. Thanks everyone for the help!
If you are using a version of cabal-install >= 3.0 (check with cabal --version), then, instead of creating a cabal package, you can move to an empty folder and type:
cabal install --lib --package-env . random
This creates a .ghc.environment file in the folder. ghci sessions started inside that folder will pick it up, and they will be able to import System.Random.
If that works correctly, you might want to install "random" globally so that any invocation of ghci can use it:
cabal install --lib random
This creates/modifies the global environment file located at ~/.ghc/$ARCH-$OS-$GHCVER/environments/default.
The System.Random module is part of the random package, not of the base package. You thus should install it. If you for example use cabal, you can install it with cabal install random.
If you use Haskell stack for example, you can add it to your package-name.cabal file:
-- …
build-depends:
base >=4.7 && <5
, random >=1.0 && <2
I'm using Windows 10. I downloaded Cabal.exe, put it in my ghc-8.8.1\bin\ directory and ran it with command cabal update. It did nothing for a while, then it ended without any messages.
Now when I run cabal install random (trying to install package "random"), I get the following error:
cabal: Error: Could not find module: System.Random with any suffix:
["gc","chs","hsc","x","y","ly","cpphs","hs","lhs","hsig","lhsig"]. If the
module is autogenerated it should be added to 'autogen-modules'.
I have no clue why it does this.
I also tried installing the package manually (following the steps from here) - downloaded package random-1.1.tar.gz and ran:
cd filepathtopackage
c:\Program Files\Apps\ghc-8.8.1\bin\runhaskell.exe Setup configure
This for a change gives me the following error:
| C:\Program Files\Apps\ghc-8.8.1\lib\Cabal-3.0.0.0\HSCabal-3.0.0.0.o: unknown symbol '.file'
Setup: Setup: unable to load package 'Cabal-3.0.0.0'
When I run ghc-pkg list, Cabal is in there, so again, no clue why it does this.
Does anyone have any tips on how to resolve this?
environment:
ubuntu14.04
haskell platform 2014 2.0.0 (ghc 7.8.3,cabal 1.18.13)
stackage:Stackage build for GHC 7.8 + Haskell Platform, 2014-09-24, exclusive
according to http://www.yesodweb.com/page/quickstart , I ran:
dsu#dsu-G41MT-D3:~$ cabal install alex happy yesod-bin
Resolving dependencies...
Configuring ansi-terminal-0.6.1.1...
Configuring alex-3.1.3...
Downloading unix-time-0.3.4...
Failed to install ansi-terminal-0.6.1.1
Last 10 lines of the build log ( /home/dsu/.cabal/logs/ansi-terminal-0.6.1.1.log ):
Configuring asn1-types-0.2.3...
Configuring auto-update-0.1.1.3...
Failed to install alex-3.1.3
Last 10 lines of the build log ( /home/dsu/.cabal/logs/alex-3.1.3.log ):
Failed to install asn1-types-0.2.3
Configuring base-unicode-symbols-0.2.2.4...
Last 10 lines of the build log ( /home/dsu/.cabal/logs/asn1-types-0.2.3.log ):
Failed to install auto-update-0.1.1.3
Last 10 lines of the build log ( /home/dsu/.cabal/logs/auto-update-0.1.1.3.log ):
Configuring base64-bytestring-1.0.0.1...
Configuring blaze-builder-0.3.3.4...
Failed to install base-unicode-symbols-0.2.2.4
Last 10 lines of the build log ( /home/dsu/.cabal/logs/base-unicode-symbols-0.2.2.4.log ):
Failed to install unix-time-0.3.4
Last 10 lines of the build log ( /home/dsu/.cabal/logs/unix-time-0.3.4.log ):
cabal: /home/dsu/.cabal/logs/unix-time-0.3.4.log: does not exist
It simply says "fail to install" and give no any hints.Why use of stackage still has these problems?
This generic cabal debugging advice usually finds the problem....
Update the cabal database, try again
cabal update
cabal install ....
Try to install the dependency with the problem separately.... Looking above, it seems I see a few lines that start with "Failed to install....", test these separately.
cabal install base-unicode-symbols
Recurse if necessary.
Download the package that fails,
cabal unpack base-unicode-symbols
cd base-unicode-symbols-*
Configure to see if its dependencies are all loaded
cabal configure
If not, recurse into the troubled package.
Try to build the package
cabal build
If it doesn't work, you now have useful error messages. If you can fix the problem, great, else repost the information here.
Install
cabal install
In more drastic cases, you might want to delete (actually, just move it in case you want it back) your ~/.cabal/* contents, or your ~/.ghc/* contents, but leave this as a last resort, because you will have to reinstall all cabal packages. Also, you might want to keep the contents of ~/.cabal/bin/*.
I just updated Stackage Server to use FP Complete's Hackage mirror (which is Amazon S3 powered) instead of Hackage itself. That should make it completely resilient to Hackage downtime. Thanks for raising this issue, we definitely want Stackage to have better uptime guarantees than Hackage.
I've encountered the same problem. I have resolved it by temporarily deleting my HTTP_PROXY environment variable to not have cabal try to connect through an unreachable server.
I'm new with Haskell and have trouble with its package.
I want to import System.Random but
Could not find module `System.Random'
Then I tried to import System but
Could not find module `System'.
It is a member of the hidden package `haskell98-2.0.0.0'.
I tried to search this problem, but those solutions still don't work.
As this said, I tried to install cabal on my Mac OS X using MacPort, but
Error: The following dependencies were not installed: ghc
Error: Status 1 encountered during processing.
I have installed Haskell Platform and can use ghci in command-line.
GHCi, version 7.2.1
Then I tried to use ghc-pkg expose haskell98-2.0.0.0 as this one says.
But this time, I can't even run ghci.
Top level:
Ambiguous interface for `Prelude':
it was found in multiple packages: base haskell98-2.0.0.0
So, what can I do without using cabal?
The System.Random module belongs to the random package, which is no longer included with GHC as of version 7.2.1.
I'm not sure what to do about your Cabal problem, as I'm not familiar with Mac OS X, but I'd recommend getting that to work first. Installing random should then be trivial using Cabal.
As a possible workaround, you might want to consider using an older version of GHC.
the cabal incantation:
cabal install random
The answer here is a little bit dated and would lead to a global install and should be discouraged.
A better approach will be to add the random package as dependency in the .cabal file.
Something like this:
build-depends: base ^>=4.13.0.0 --base package
, random -- random package where System.Random can be found
cabal repl -b random # -b is short for --build-depends
This answer was based on another stackoverflow thread here. Basically it installs the package random as a dependency of your project rather than installing it globally. Packages are installed globally if you just write cabal install random - which we dont usally want.