How can I download NML on mac?

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

How can I download NML on mac?

Post by HoratioNelson »

Hello.

I have recently become enticed by the prospect of coding NewGRFs and I have downloaded NML and python, but I was wondering how to install it on python. I have tried many different ways, but there is no section on downloading it for mac in the Wiki. I think I have installed NML in my terminal, but it does not work there.

Thank you very much.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5656
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: How can I download NML on mac?

Post by andythenorth »

https://newgrf-specs.tt-wiki.net/wiki/N ... rted#macOS

There's more than one way to do it, but all of them are via Terminal.

You'll need python 3, which Apple do ship bundled on recent macOS. However 'python' in Terminal is usually aliased to the python2.7 that Apple also ship bundled.

I install my own python 3 using the official python mac installer, and set the path to it in ~/.zshrc

I also use a virtualenv to install nmlc and the other dependencies into, as it avoids any clashes with any other python projects.

It's fiddly, but the individual steps are quite learnable.
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

I have opened the .zshrc file. Now, what do I do?
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

By the way, I enjoy the FIRS Industry Replacement Set.

Especially Steeltown.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5656
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: How can I download NML on mac?

Post by andythenorth »

HoratioNelson wrote: 09 Apr 2022 13:00 I have opened the .zshrc file. Now, what do I do?
Hmm, I can't remember if you actually need to set the path.

If you installed one of the official python binaries from here https://www.python.org/downloads/macos/ it might have set the path for you.

What happens if you type 'python3' in Terminal?

Also what happens if paste '/Library/Frameworks/Python.framework/Versions/3.10/bin/python3' in Terminal?
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

If I type in python3, it starts python and gives me the">>>"

If I paste /Library/Frameworks/Python.framework/Versions/3.10/bin/python3, it does the same thing.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5656
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: How can I download NML on mac?

Post by andythenorth »

HoratioNelson wrote: 10 Apr 2022 01:23 If I type in python3, it starts python and gives me the">>>"

If I paste /Library/Frameworks/Python.framework/Versions/3.10/bin/python3, it does the same thing.
I would make a virtualenv next. This is entirely optional, but a virtualenv creates an isolated copy of a python environment into which you can install nmlc and it's dependencies.

It's then easy to delete a virtualenv if you don't need it, and it avoids any effects to/from other python projects.

https://docs.python.org/3/library/venv.html

I would try something like this.

First cd to the directory you want to make the virtualenv, (somewhere in Home or Documents or Desktop usually).

Then:

Code: Select all

/Library/Frameworks/Python.framework/Versions/3.10/bin/python3  -m venv py310
This will create a virtualenv named py310. You then activate this with.

Code: Select all

 source py310/bin/activate
Then you do:

Code: Select all

pip install nml
Pip will warn about wanting pip itself upgraded, which you can optionally do, but it's not essential.

Then check that nmlc is installed and in the path with this:

Code: Select all

which nmlc
Then you have working nmlc, which you can test with

Code: Select all

nmlc --help
You have to activate the virtualenv every time you start a new Terminal window, or reboot the Mac. If you ever want to deactivate it for any reason, just type 'deactivate'.

You can skip the virtualenv and just pip install nml, but it's less clean long-term.
Last edited by andythenorth on 10 Apr 2022 16:17, edited 1 time in total.
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

If I type in "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -m py310" it gives me a syntax error.
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

If I type in "nmlc --help" it gives me the different commands for nml, so how would I use it in terminal and export the code as a .nml file?
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5656
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: How can I download NML on mac?

Post by andythenorth »

HoratioNelson wrote: 10 Apr 2022 14:14 If I type in "/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -m py310" it gives me a syntax error.
Oops, I pasted a bad command sorry, should have been

Code: Select all

/Library/Frameworks/Python.framework/Versions/3.10/bin/python3  -m venv py310
HoratioNelson wrote: 10 Apr 2022 15:52 If I type in "nmlc --help" it gives me the different commands for nml, so how would I use it in terminal and export the code as a .nml file?
To compile a grf from a .nml file. do something like:

Code: Select all

nmlc --grf=foo.grf foo.nml
You might need a language (translations) file as well, can't remember :)
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

I have created the virtualenv. If I type in "python3" and write some code, will I be able to export it as a .nml file so I can compile it into a .grf file?
Also, what is a good tool for drawing sprites?
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5656
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: How can I download NML on mac?

Post by andythenorth »

HoratioNelson wrote: 10 Apr 2022 16:42 I have created the virtualenv. If I type in "python3" and write some code, will I be able to export it as a .nml file so I can compile it into a .grf file?
You write the nml code into a text file, saved with .nml extension. Then nmlc compiles that for you into a .grf.

You can use TextEdit (in plain text mode) or BBEdit or Coda or one of the many other Mac text editors to edit the .nml file. Or even XCode, although that's massive overkill.
Also, what is a good tool for drawing sprites?
I use Photoshop, but that's expensive. I've also used Pixelmator, but I don't know if it can save paletted 8 bit pngs, which is the most common format for sprites (there are alternatives).
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

Hopefully, this will be my last question. No guarantees, though.
How can I get the option to save the text in text edit as a .nml file?
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

If I do that, it saves it as Untitled.nml.txt. If I uncheck the "if no extension is provided, use .txt" box and attempt to compile it, it tells me "nmlc ERROR: Input file "Untitled.nml" does not exist"
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

If I rename it to "untitled.nml" through get info and try to compile it, it gives me an nmlc error and tells me that the document does not exist.
User avatar
HoratioNelson
Engineer
Engineer
Posts: 14
Joined: 09 Apr 2022 00:52
Location: Florida

Re: How can I download NML on mac?

Post by HoratioNelson »

It will do the same thing through terminal.
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: le_harv and 19 guests