Run simple swift script from terminal with imported library - swift

I would like to migrate some python code to swift which includes numpy and found a library called Matft.
I'm doing this on a VM and Xcode is very slow, so it would be great to avoid that and use the terminal (ideally run the .swift from a shared folder), but than I got the error: "no such module".
I found that I could pass -I flag and specify a path for the lib, but does not working for me.
Can someone give an easy explanation how to import external library in such situation?

Related

pyodbc has a .pyi file but mypy doesn't see the stub file

pyodbc has a .pyi file but when running pytest-mypy, I have this error:
__________________________________________________________________________________________________ connexion.py __________________________________________________________________________________________________
3: error: Cannot find implementation or library stub for module named "pyodbc"
3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
_
This should only happen when the library doesn't have stub files but it appears there are stub files. What should I do?
I'm using Python 3.10.2 and i've updated pyodbc to the latest version (pyodbc==4.0.34)
Let's assume your python is installed in /usr. In that case, your python executable will be in /usr/bin, and any libraries you install with pip will be installed in /usr/lib/python3.10/site-packages. In this case, all the sources for pyodbc can be found in /usr/lib/python3.10/site-packages/pyodbc.
Following this pattern we would expect to find type stubs in /usr/lib/python3.10/site-packages/pyodbc.pyi, but there is an issue in pyodbc, so that the stubs are actually installed in /usr/pyodbc.pyi.
In order to pick up this path, you will need to modify settings in your development environment. In Linux, try setting PYTHONPATH=/usr in your environment. The link mentioned in rogdham's comment includes others' comments on how to make this work in VS Code. Other development environments should support similar workarounds.

Programming in Swift on Linux

I would like to prepare the environment for working with Swift on Ubuntu 16.04.
I installed Swift and Atom editor.
I installed the Script package, which allows me to run code from the Atom editor.
Generally it is nice when I compile and run one file (Ctrl+Shift+B shortcut).
The problem is when I would like to build a project composed of several files.
Classes defined in the other files (not the one I compile) are not visible (compilation error).
Is it possible to configure the editor to compile and run the entire project?
How to import external library, eg ObjectMapper ?
You can use the Atom package build. It allows you to create custom build commands and such by using common build providers. You can build with a Makefile or JSON or CSON or YAML or even Javascript. It provides enough flexibility that you can build just about anything. Just make your build file so that it points to all the files to build with the right compiler (probably swiftc in your case). With a Javascript build file, you can even specify a command to run before and after the build, say, to run your newly built program.
There's a great open source project I have been watching called Marathon. It's a package manager and they have been Working on a deployment on linux. I'm not sure how much success they have had, but you can follow along here and maybe help out.
https://github.com/JohnSundell/Marathon/issues/37
Edit: It looks like it does work on linux!
git clone https://github.com/JohnSundell/Marathon.git
$ cd Marathon
$ swift build -c release
$ cp -f .build/release/Marathon /usr/local/bin/marathon
For dependencies, you should use Swift Package Manager.
You can check how Vapor is built - it is prepared for build apps for Ubuntu too.
Also, Vapor toolbox would help you with other projects
https://docs.vapor.codes/2.0/getting-started/install-on-ubuntu/
You can build a Swift project using VS Code + Swift Development Environment extension
If steps on the link above are not clear enough, I've put more details in a blog post

Swift Linux. Error: no such module 'Dispatch'

I use Ubuntu 15.10
I compiled swift-corelibs-libdispatch, get file libdispatch.so
But still if I use "import Dispatch" get an error "no such module 'Dispatch'"
How can I add this module to Swift?
One way to accomplish this would be to set up a system module for libdispatch and use swift build. See https://github.com/apple/swift-package-manager/blob/13d682a63ea01246dd119cd4cf5c8d90c030566d/Documentation/SystemModules.md on how to use system modules. This quesion, Importing a Swift module using a C library, may also come in handy.
I'm sure there are other ways, too. You should be able to use swift interpreter or swift compiler (swiftc), but I can't think of a way to do that off the top of my head.

Why can't pydev find the csv module?

I still cannot get PyDev and eclipse on MacOS to reliably import modules.
import csv generates an "Unresolved import:" error within PyDev; however, when I open Terminal and run the script from the interpreter it works fine.
PyDev is using the interpreter found at /usr/bin/python, which is pointing to Python 2.7.
The relevant files (csv.pyc and csv.pyo) are in /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7, which is in PYTHONPATH.
Actually, for the standard library, PyDev needs the .py files (from your description you only have the .pyc/.pyo files) -- it should give you a big warning when you try to configure an interpreter where the .py files are not available.
So, the recommended solution would be using a python distribution from http://python.org (instead of the default which comes with Mac OS) or grab the standard library from elsewhere and copy it over to where you have the standard library in Mac OS.
See the "IMPORTANT for Mac users" note at: http://pydev.org/manual_101_interpreter.html
Everytime you add a new module, you need to reconfigure the interpreter in PyDEV. Whenever you do that, don't forget to check the new module you are adding to make sure it's being added to the PYTHON PATH.
Alternatively, you can configure each project by adding the new module to it. But that means you will have to configure this on a project basis. I would do it the other way.

How can I import a .PYD module in IronPython?

I'm trying to use a python package from IronPython.
Everything works fine if I import regular python modules.
But when I try to do the following:
import win32ui
I get:
No module named win32ui
I've hunted through the code in IronPython.Runtime.Importer and there's no mention of .pyd
Anyone know a way around this?
You can check out IronClad which is working to provide this support. It may or may not work w/ your PYD of choice.
A .pyd file is a DLL. So unless IronPython (which is written in .net) can correctly load C DLLs written for CPython, you might be out of luck.
Update
In fact, according to the IronPython FAQ, you are unfortunately unable to import .pyd files:
Q: How do I build and call into PYD libraries?
A: IronPython does not support using PYDs built for CPython since they
leverage implementation details of CPython. You can get a similar
effect for new "PYD"s you would like to implement by writing them in C#
or VB and building a DLL for .NET.