[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Python
. . -> [Subject]  Python path woes
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Python path woes

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Sat 28 Jun 2008 12:16 PM (UTC)
Message
I'm writing a script file and I've broken some of the functionality into modules, but when I try to import them I get import errors. I assume this is because MC runs the interpreter from its working directory and thus the interpreter can't find my module.

Is there any way to tell it where to look? (I don't want to have to put my module in site-packages)...

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (21,386 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 28 Jun 2008 09:03 PM (UTC)
Message
I have been having some similar problems recently. The "current directory" is a pain, as it can change if the user simply browses for a file in another directory.

A couple of solutions:


ChangeDir (GetInfo(66))  --> make the current directory the MUSHclient directory


Then load your modules.

Or use something like GetInfo(66) and then add the rest of the path to it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #2 on Sat 28 Jun 2008 09:04 PM (UTC)
Message
Hmm, can MC be changed so that the interpreter runs each script from its directory?

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #3 on Sat 28 Jun 2008 09:22 PM (UTC)
Message
No, it came up before in these forums I think. Every process only has one current directory, so you can't make it specific.

However, Python is a wonderful language. Not too long ago, I read somewhere about someone who adjusted the way importing works so it would first look in a specific directory. Google a bit, you shouldn't have too much trouble finding it. Otherwise I'll see if I can find it.
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #4 on Sat 28 Jun 2008 09:31 PM (UTC)
Message
Ah, I've already done that, all you need to do is append the directory of the import files to sys.path, I just don't like hardcoding paths :)

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (21,386 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Sat 28 Jun 2008 09:37 PM (UTC)
Message
Can't you use GetInfo (66) ? That isn't a hard-coded path, it is the path currently in use.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #6 on Sat 28 Jun 2008 09:38 PM (UTC)
Message
Yes, I think I'll go with that, I was just wondering if there was a way to "fix" this. I'm not sure whether each loaded script has a path one could tweak... Anyway, I'll use GetInfo, thanks for your help :)

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #7 on Sat 28 Jun 2008 09:43 PM (UTC)
Message
Hmm, that points to the world file directory, which assumes the script is in that directory... Could you at least add a "Script directory" directive there? Luckily, both my world file and its script are in the same directory, so this solves it.

I'm trying to do my thesis with MUSHclient and I run into a few problems on the first day :P By the way, it's GetInfo(67), small oversight there.

Thanks again for your help!

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (21,386 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Sat 28 Jun 2008 10:05 PM (UTC)
Message
66 is the application directory, like I said. I think that is always a fully-qualified path name, which is why I used it.

67 is the world file directory. That could be anywhere, it depends where you put your world file.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #9 on Sat 28 Jun 2008 10:12 PM (UTC)
Message
Also, since I am not sure if you want to refer to own utility libraries which aren't MUSH specific, or whether you are just trying to split your plugin over multiple files, I think the <include> tag may also be a viable alternative. I use it for one of my plugins which have around 2500 triggers in it, and where having it all in one file would be... TOO bulky.

It's essentially a concatenation of all scripts over the files into one buffer, which is loaded as one file. As such, it is all the same namespace and can't be seen seperately from within Python. But for my uses, that's usually more than plenty. =)
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #10 on Sun 29 Jun 2008 12:01 AM (UTC)
Message
Ah, I can't use that because it's a plain script file, not a plugin file. The path thing should work well, thanks!

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


6,055 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]