Unable to compile my C Extension on Windows: unresolved external link errors

2021-11-12 Thread Marco Sulla
I have no problem compiling my extension under Linux and MacOS. Under
Windows, I get a lot of

Error LNK2001: unresolved external symbol PyErr_SetObject

and so on.

I post the part of my setup.py about the C Extension:

extra_compile_args = ["-DPY_SSIZE_T_CLEAN", "-DPy_BUILD_CORE"]
undef_macros = []

setuptools.Extension(
ext1_fullname,
sources = cpython_sources,
include_dirs = cpython_include_dirs,
extra_compile_args = extra_compile_args,
undef_macros = undef_macros,
)

Here is the full code:
https://github.com/Marco-Sulla/python-frozendict/blob/master/setup.py

Steps to reproduce: I installed python3.10 and VS compiler on my
Windows 10 machine, then I created a venv, activated it, run

pip install -U pip setuptools wheel

and then

python setup.py bdist_wheel
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to compile my C Extension on Windows: unresolved external link errors

2021-11-12 Thread Gisle Vanem

Marco Sulla wrote:


Error LNK2001: unresolved external symbol PyErr_SetObject

and so on.

I post the part of my setup.py about the C Extension:

extra_compile_args = ["-DPY_SSIZE_T_CLEAN", "-DPy_BUILD_CORE"]


Shouldn't this be "-DPy_BUILD_CORE_MODULE"?


--
--gv
--
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to compile my C Extension on Windows: unresolved external link errors

2021-11-12 Thread Marco Sulla
On Fri, 12 Nov 2021 at 15:55, Gisle Vanem  wrote:
> Marco Sulla wrote:
> > Error LNK2001: unresolved external symbol PyErr_SetObject
> >
> > and so on.
> >
> > I post the part of my setup.py about the C Extension:
> >
> > extra_compile_args = ["-DPY_SSIZE_T_CLEAN", "-DPy_BUILD_CORE"]
>
> Shouldn't this be "-DPy_BUILD_CORE_MODULE"?

I tried it, but now I get three

error C2099: initializer is not a constant

when I try to compile dictobject.c. Yes, my extension needs dictobject.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to compile my C Extension on Windows: unresolved external link errors

2021-11-12 Thread Chris Angelico
On Sat, Nov 13, 2021 at 3:28 AM Marco Sulla
 wrote:
>
> On Fri, 12 Nov 2021 at 15:55, Gisle Vanem  wrote:
> > Marco Sulla wrote:
> > > Error LNK2001: unresolved external symbol PyErr_SetObject
> > >
> > > and so on.
> > >
> > > I post the part of my setup.py about the C Extension:
> > >
> > > extra_compile_args = ["-DPY_SSIZE_T_CLEAN", "-DPy_BUILD_CORE"]
> >
> > Shouldn't this be "-DPy_BUILD_CORE_MODULE"?
>
> I tried it, but now I get three
>
> error C2099: initializer is not a constant
>
> when I try to compile dictobject.c. Yes, my extension needs dictobject.

Are you sure that you really need Py_BUILD_CORE? Here's what the code
has to say about it:

https://github.com/python/cpython/blob/main/Include/pyport.h#L17

Py_BUILD_CORE: Build Python core. Give access to Python internals, but
should not be used by third-party modules.

If your extension truly needs to reach into the internals of CPython,
then you're going to have to figure a lot of things out for yourself,
including how to make sure it works on every platform. A more
productive approach would be to stick to the actual API:

https://docs.python.org/3/c-api/stable.html

What is it that doesn't work without Py_BUILD_CORE?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to compile my C Extension on Windows: unresolved external link errors

2021-11-12 Thread Marco Sulla
Chris? Maybe I'm dreaming X-D

On Fri, 12 Nov 2021 at 17:38, Chris Angelico  wrote:
> Are you sure that you really need Py_BUILD_CORE?

Yes, because I need the internal functions of `dict`. So I need to
compile also dictobject.c and include it. So I need that flag.

This is the code:

https://github.com/Marco-Sulla/python-frozendict.git

On Linux and MacOS it works like a charme. On Windows, it seems it does not find
python3.lib. I also added its path to the PATH variable
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to compile my C Extension on Windows: unresolved external link errors

2021-11-12 Thread Chris Angelico
On Sat, Nov 13, 2021 at 7:01 AM Marco Sulla
 wrote:
> On Fri, 12 Nov 2021 at 17:38, Chris Angelico  wrote:
> > Are you sure that you really need Py_BUILD_CORE?
>
> Yes, because I need the internal functions of `dict`. So I need to
> compile also dictobject.c and include it. So I need that flag.
>
> This is the code:
>
> https://github.com/Marco-Sulla/python-frozendict.git
>

Ah, gotcha.

Unfortunately that does mean you're delving deep into internals, and a
lot of stuff that isn't designed for extensions to use. So my best
recommendation is: dig even deeper into internals, and duplicate how
the core is doing things (maybe including another header or
something). It may be that, by declaring Py_BUILD_CORE, you're getting
a macro version of that instead of the normal exported function.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Getting Directory of Command Line Entry Point For Packages

2021-11-12 Thread Abdur-Rahmaan Janhangeer
Greetings list,

Let's say i created a package named miaw

miaw also has a cli command called miaw

miaw prints files and folders in the directory it is called in

except that when miaw is used, it prints the files and folders in
site-packages

This is an analogy for  a package i have.

Well forgetting about the lines above, how do i get the path from
which miaw the command is called from?

Thanks

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting Directory of Command Line Entry Point For Packages

2021-11-12 Thread David L Neil via Python-list
On 13/11/2021 10.51, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
> 
> Let's say i created a package named miaw
> 
> miaw also has a cli command called miaw
> 
> miaw prints files and folders in the directory it is called in
> 
> except that when miaw is used, it prints the files and folders in
> site-packages
> 
> This is an analogy for  a package i have.
> 
> Well forgetting about the lines above, how do i get the path from
> which miaw the command is called from?

try:

file_path = __file__
print( file_path )

and process file_path as-required.
-- 
Regards =dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting Directory of Command Line Entry Point For Packages

2021-11-12 Thread dn via Python-list
On 13/11/2021 10.51, Abdur-Rahmaan Janhangeer wrote:
> Greetings list,
> 
> Let's say i created a package named miaw
> 
> miaw also has a cli command called miaw
> 
> miaw prints files and folders in the directory it is called in
> 
> except that when miaw is used, it prints the files and folders in
> site-packages
> 
> This is an analogy for  a package i have.
> 
> Well forgetting about the lines above, how do i get the path from
> which miaw the command is called from?

try:

file_path = __file__
print( file_path )

and process file_path as-required.

-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to compile my C Extension on Windows: unresolved external link errors

2021-11-12 Thread Marco Sulla
On Fri, 12 Nov 2021 at 21:09, Chris Angelico  wrote:
>
> On Sat, Nov 13, 2021 at 7:01 AM Marco Sulla
>  wrote:
> > On Fri, 12 Nov 2021 at 17:38, Chris Angelico  wrote:
> > > Are you sure that you really need Py_BUILD_CORE?
> >
> > Yes, because I need the internal functions of `dict`. So I need to
> > compile also dictobject.c and include it. So I need that flag.
> >
> > This is the code:
> >
> > https://github.com/Marco-Sulla/python-frozendict.git
> >
>
> Ah, gotcha.
>
> Unfortunately that does mean you're delving deep into internals, and a
> lot of stuff that isn't designed for extensions to use. So my best
> recommendation is: dig even deeper into internals, and duplicate how
> the core is doing things (maybe including another header or
> something). It may be that, by declaring Py_BUILD_CORE, you're getting
> a macro version of that instead of the normal exported function.

I've not understood what I have to do in practice but anyway, as I
said, Py_BUILD_CORE works on Linux and MacOS. And it works also on
Windows. Indeed dictobject.c is compiled. The only problem is in the
linking phase, when the two objects should be linked in one library,
_the_ library. It seems that on Windows it doesn't find python3.lib,
even if I put it in the path. So I get the `unresolved external link`
errors.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting Directory of Command Line Entry Point For Packages

2021-11-12 Thread Greg Ewing

On 13/11/21 10:51 am, Abdur-Rahmaan Janhangeer wrote:

ow do i get the path from
which miaw the command is called from?


What exactly do you mean by "called from"?

If you want the user's working directory, os.getcwd() will
give you that.

If you want something else, you'll have to give us more
details.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Looking to Partner with Python Developer with Apple M1 Chip

2021-11-12 Thread Sarkis Dallakian
 Greetings,

I'm looking for someone who has the latest Apple with M1 Chip and who can
partner with me to build a software I wrote called PyRx. This is based on
wxPython and can provide you with a steady source of income.

Please email me if you are interested to discuss the details.

Thank you,
Sarkis
PS: Sorry if this is not the right place to post this message.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting Directory of Command Line Entry Point For Packages

2021-11-12 Thread Abdur-Rahmaan Janhangeer
Greetings,

Well since sometimes i have this: https://github.com/shopyo/shopyo
Old versions worked as we are using it for FlaskCon
, even newer versions
until sometimes ago.

shopyo has a copy of the project which is a flask app in site-packages.
upon using shopyo new, it creates a copy of the project in the current
folder
then on running say shopyo run, it just passes commandline args flask run
under the hood

Only thing is that os.getcwd is giving the path of site-packages and not
the directory from
which the command is run from. See the run command's source here:
https://github.com/shopyo/shopyo/blob/19dc2ee03ff0a6a0dca3237f80a11478ee2dbe46/shopyo/api/cmd_helper.py#L313

Same goes for other commands. I wanted to know how to get the directory
from which the
command is called from. Thanks


Else i assume you are the author of this article
 as i
was compiling a list of articles

and guess that it might be.

Kind Regards,

Abdur-Rahmaan Janhangeer
about  | blog

github 
Mauritius
-- 
https://mail.python.org/mailman/listinfo/python-list