Unable to import into Python

There is no “aspose.cad” to import in Python anymore. I had it in an older version, in Windows. However I am running Ubuntu now and just pip installed the latest version of aspose-cad. My original script had an import statement - “import aspose.cad as cad”, but that doesn’t work now.
What has changed?

>>> import aspose
>>> dir(aspose)
['AsposeModuleFinder', 'AsposeModuleLoader', 'SourceFileLoader', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_load', '_platform_suffixes', 'foreach_file', 'im', 'inspect', 'os', 're', 'sys', 'sysconfig', 'util']
>>> dir(aspose.AsposeModuleLoader)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_import_file', '_load_native_module', '_prepare_as_package', '_register_additional_classes', 'aspose_native_lib_dir', 'aspose_py_modules', 'load_module']
>>> import aspose
>>> dir(aspose.util)
['LazyLoader', 'Loader', 'MAGIC_NUMBER', '_LazyModule', '_RAW_MAGIC_NUMBER', '__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_find_spec', '_find_spec_from_path', '_imp', '_incompatible_extension_module_restrictions', '_resolve_name', 'cache_from_source', 'decode_source', 'find_spec', 'module_from_spec', 'resolve_name', 'source_from_cache', 'source_hash', 'spec_from_file_location', 'spec_from_loader', 'sys', 'threading', 'types']
>>> 
>>> 
>>> 
>>> 
>>> import aspose-cad
  File "<stdin>", line 1
    import aspose-cad
                 ^
SyntaxError: invalid syntax
>>> import aspose.cad
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'aspose.cad'
>>>

@vvevans

It seems that you are experiencing issues with importing the aspose.cad module in your Python environment after switching to Ubuntu. The aspose.cad library is indeed available for Python, but there may have been changes in how it is structured or installed.

Here are a few steps you can take to troubleshoot and resolve the issue:

  1. Check Installation: Ensure that you have installed the aspose-cad package correctly. You can do this by running the following command in your terminal:

    pip show aspose-cad
    

    This command will display information about the installed package. If it is not installed, you can install it using:

    pip install aspose-cad
    
  2. Correct Import Statement: The correct import statement for the Aspose.CAD library in Python should be:

    import aspose.cad
    

    Make sure you are not using any hyphens or incorrect syntax in your import statement, as Python does not allow hyphens in module names.

  3. Python Version: Ensure that you are using a compatible version of Python. Aspose.CAD for Python is compatible with Python 3.x. You can check your Python version by running:

    python --version
    
  4. Virtual Environment: If you are using a virtual environment, make sure it is activated before running your script. This ensures that the correct packages are available.

  5. Documentation and Support: If the issue persists, you may want to refer to the official Aspose documentation for further guidance or check the Aspose support forums for similar issues reported by other users.

If you follow these steps and still encounter problems, please provide any error messages you receive, and I can assist you further.

Sources:
[1]: FAQ - Aspose Documentation
[2]: Aspose.CAD Product Family

@vvevans,
Hi,
we have logged CADPYTHON-248 ticket to investigate this issue.

1 Like

@vvevans,
Hi.
We tested this case and found no issues for Ubuntu. Could you please ensure that library is properly installed and test if this example works?

from aspose.cad import *
from aspose.cad.fileformats.cad.cadobjects import *
import aspose.cad as cad
from aspose.cad.fileformats.cad import *
from aspose.cad.fileformats.cad.cadconsts import *
from aspose.cad.imageoptions import *
from aspose.pycore import cast

if __name__ == '__main__':
    im = cad.Image.load("file.dxf")
    im.save("result.pdf", PdfOptions())
    image = Image.load("file.dxf")

    rasterizationOptions = CadRasterizationOptions()
    rasterizationOptions.page_height = 1600.0
    rasterizationOptions.page_width = 1600.0

    pdfOptions = PngOptions()
    pdfOptions.vector_rasterization_options = rasterizationOptions
    pdfOptions.user_watermark_text = "watermark"
    pdfOptions.user_watermark_color = Color.green
    image.save("result.png", pdfOptions)

Below are my logs from my terminal. Per the aspose.com website, the way to install aspose.cad for Python is via the Pip package manager, which is what I did. However, once installed, nothing follows the examples on the website:

❯ source .venv/bin/activate
 ❲p❳ .venv  ~/Code/MGM                                                                                           09:15:24  vve1505
❯ uv pip list
Package    Version
---------- -------
aspose-cad 24.8.0
 ❲p❳ .venv  ~/Code/MGM                                                                                           09:15:34  vve1505
❯ python -i
Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from aspose.cad import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'aspose.cad'
>>> from aspose import *
>>> dir(aspose)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'aspose' is not defined
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>> import aspose
>>> dir(aspose)
['AsposeModuleFinder', 'AsposeModuleLoader', 'SourceFileLoader', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_load', '_platform_suffixes', 'foreach_file', 'im', 'inspect', 'os', 're', 'sys', 'sysconfig', 'util']
>>>

@vvevans,
we will look at this one more time and come back with results. Could you please try to downgrade and try previous versions of package, e.g., 24.7, 24.6, 24.5? Could you please try whether Python 3.11 or 3.10 works? Please share also which is your Ubuntu version. Thank you.

I will try those things you said and report back.
I’m running Ubuntu 24.04 desktop. Stand by.

Ok - I went back to version 24.3 and it finally worked; before that, I tried 24.7 and 24.5 and it wouldn’t import as expected.

I had also created a new virtual environment using Python 3.11.3. Results below:

 ❲p❳ .3_11_venv  ~/Code/MGM                                                                                      13:31:46  vve1505
❯ uv pip list
Package    Version
---------- -------
aspose-cad 24.3.0
 ❲p❳ .3_11_venv  ~/Code/MGM                                                                                      13:31:55  vve1505
❯ python -i
Python 3.11.9 (main, Aug 14 2024, 05:07:28) [Clang 18.1.8 ] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import aspose-cad as cad
  File "<stdin>", line 1
    import aspose-cad as cad
                 ^
SyntaxError: invalid syntax
>>> import aspose.cad as cad
>>>

@vvevans,
OK, could you raise up versions on your side step by step? Please try 24.4 for Python 3.11, 24.5, etc. Which version will stop working as expected for you?

We tested on the other PC and see no issues again as per examples below (Python 3.11, 24.8).
1_.png (61.2 KB)
2_.png (7.5 KB)

Ok, so I did as you asked. It appears that the issue presents itself with Python version 3.12.
I installed aspose-cad versions 24.3, .4, - all the way through 24.8 with Python 3.11 (thru version 3.11.9) and it worked each time. As soon as I upgraded to Python 2.12.1, I could no longer import aspose.cad properly.

1 Like

@vvevans,
Thank you very much. So the latest 24.8 version works for Python 3.11, good to hear. It is mentioned on the page of the product - aspose-cad · PyPI - that it requires Python <3.12, >=3.5, so it is not expected to work for 3.12.

I apologize - I had not seen the version requirement. Anyway, thanks for the help again - your product has worked out great!

1 Like

@vvevans,
It’s OK, thank you for your time spent for testing and for kind words :slight_smile: We are also going to check if we can support Python 3.12 in the upcoming releases.

Hey, I know I worked through this, but I’ve run into another problem that I don’t know if it is related or not.

After everything we previously went through, testing versions, etc. I setup an Ubuntu Server VM and loaded the same Python and Aspose.CAD for python versions that ended up working. I’m trying to setup an environment for a customer, who will later purchase the license if I can get this working.

When attempting to run my script to convert DWF files to PDF, I’m receiving the following error:

Process terminated. Couldn't find a valid ICU package installed on the system. Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.
   at System.Environment.FailFast(System.String)
Process terminated. Process terminated. Process terminated. Process terminated. Couldn't find a valid ICU package installed on the system.

What additional information do you need to help me troubleshoot?

@vvevans,
Hi,
probably, this relates to libicu package or .NET SDK installation. Could you please consider these options?

Resolved. Actually ended up being related to libssl and the fact that my script (which was created on Windows, but now running on linux) was using "", instead of “/”.

Thanks for the direction - always helpful.

1 Like

@vvevans,
we are happy to help :slight_smile: