# Importing obj files

**URL:** https://forum.compas-framework.org/t/importing-obj-files/326
**Category:** compas
**Created:** [April 6, 2020, 8:27am UTC](https://forum.compas-framework.org/t/importing-obj-files/326 "2020-04-06T08:27:25Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Pirouz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Pirouz](https://forum.compas-framework.org/u/Pirouz)
#### Post date: [April 6, 2020, 8:27am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/1 "2020-04-06T08:27:25Z")

</div>

Hi there,

I am trying to import the stanford bunny (which I have downloaded as an obj file already) using the following:

```auto
bunny=compas.files.obj.OBJReader(filePath)

```

but I constantly get the following error message:

> Blockquote  
> bunny=compas.files.obj.OBJReader(filePath)

AttributeError: module ‘compas’ has no attribute ‘files’

> Blockquote

ps. I have made sure that compas is imported by checking its version (0.11.0)

Any tip is appreciated.

---

<div class="post-metadata">

### Author: ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)
#### Post date: [April 6, 2020, 8:51am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/2 "2020-04-06T08:51:53Z")

</div>

are you trying to get the raw data or create a mesh?

if you are trying to get the raw data:

```python
from compas.files import OBJ
obj = OBJ(filepath)
obj.read()
vertices = obj.vertices
faces = obj.faces
edges = obj.lines

```

if you want to create a mesh:

```python
from compas.datastructures import Mesh
bunny = Mesh.from_obj(filepath)

```

let me know if that doesn’t work…

---

<div class="post-metadata">

### Author: ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)
#### Post date: [April 6, 2020, 9:26am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/3 "2020-04-06T09:26:27Z")

</div>

unless you specifically need this version, it might also be a good idea to update compas. current version is `0.15.5`…

---

<div class="post-metadata">

### Author: ![Pirouz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Pirouz](https://forum.compas-framework.org/u/Pirouz)
#### Post date: [April 6, 2020, 9:27am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/4 "2020-04-06T09:27:56Z")

</div>

Hi, thanks for your prompt response! Trying to read an existing mesh and get its raw data (vertices and faces) in this case. The first method didn’t work (vscode complains about 4 ‘problems’):

> Blockquote  
> Instance of ‘OBJ’ has no ‘read’ member  
> Instance of ‘OBJ’ has no ‘vertices’ member  
> Instance of ‘OBJ’ has no ‘faces’ member  
> Instance of ‘OBJ’ has no ‘lines’ member  
> Blockquote

and it gives the following error message in the output:

> Blockquote  
> C:\Users\pnourian\Documents\bunny.obj  
> Traceback (most recent call last):  
> File “c:\Users\pnourian\surfdrive\CONFIGRAPHIX\_Software\_2019\Genesis\_Houdini\Houdini\_Visualization\20\_PythonHoudini\_Setup\PY\TopoVoxelization.py”, line 18, in   
> obj = OBJ(filepath)  
> File “C:\Users\pnourian\Anaconda3\lib\site-packages\compas\files\obj.py”, line 29, in **init**  
> self.reader = OBJReader(filepath)  
> File “C:\Users\pnourian\Anaconda3\lib\site-packages\compas\files\obj.py”, line 103, in **init**  
> self.open()  
> File “C:\Users\pnourian\Anaconda3\lib\site-packages\compas\files\obj.py”, line 113, in open  
> with open(self.filepath, ‘r’) as fh:  
> FileNotFoundError: [Errno 2] No such file or directory: ‘C:\Users\pnourian\Documents\bunny.obj’  
> Blockquote

---

<div class="post-metadata">

### Author: ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)
#### Post date: [April 6, 2020, 9:36am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/5 "2020-04-06T09:36:55Z")

</div>

the first set of errors is related to your COMPAS version. my suggestion was based on the latest version (`0.15.5`) which includes some small changes to the readers…

i would just update COMPAS, but if you prefer using the version you have, the code would be something like this:

```python
obj = OBJ(filepath)
vertices = obj.parser.vertices
faces = obj.parser.faces

```

for the second error, could you print the `filepath` variable and post it here?

---

<div class="post-metadata">

### Author: ![Pirouz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Pirouz](https://forum.compas-framework.org/u/Pirouz)
#### Post date: [April 6, 2020, 9:41am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/6 "2020-04-06T09:41:03Z")

</div>

I don’t need to use this version; I wanted the most recent version; have reinstalled everything a couple of days ago. I am surprised to see that my compas is a retro version! I just did “conda update compas” in my terminal and strangely i get the same version:

```auto
import os
import numpy as np
import scipy as sp
import compas as compas
import pandas as pd 
folderPath=os.getcwd()
# print(folderPath)
print(compas. __version__ )    
filepath=r'C:\Users\pnourian\Documents\bunny.obj'

```

---

<div class="post-metadata">

### Author: ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)
#### Post date: [April 6, 2020, 9:44am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/7 "2020-04-06T09:44:05Z")

</div>

the conda update mechanism is a bit weird. just do

```bash
conda install COMPAS=0.15.5

```

---

<div class="post-metadata">

### Author: ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)
#### Post date: [April 6, 2020, 10:05am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/8 "2020-04-06T10:05:38Z")

</div>

not sure what the file path error is about. are you sure the file is available in that location?

anyway, i also noticed that the anaconda errors seem to come from your base environment.  
i would recommend not using the base environment for anything you do with conda.

think of the base environment as your conda system environment from where you create new environments, update existing ones, or revert to older versions if necessary.

therefore, even if you don’t plan on working on multiple projects in the foreseeable future, it still makes sense to sandbox your work and explorations in a separate environment.

to reset the base do

```bash
conda install --revision 1

```

to create a new environment with COMPAS installed do

```bash
conda create -n xxx python=3.7 COMPAS=0.15.5

```

replace `xxx` with the name you intend to use.  
and don’t forget to activate the environment before you use it…

---

<div class="post-metadata">

### Author: ![Pirouz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Pirouz](https://forum.compas-framework.org/u/Pirouz)
#### Post date: [April 6, 2020, 10:47am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/9 "2020-04-06T10:47:32Z")

</div>

> [@tomvanmele](#):
>
> COMPAS=0.15.5

for some reason the installation is failing repeatedly; currently trying conda install -n base compas=0.15.5 -c conda-forge

---

<div class="post-metadata">

### Author: ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)
#### Post date: [April 6, 2020, 11:21am UTC](https://forum.compas-framework.org/t/importing-obj-files/326/10 "2020-04-06T11:21:06Z")

</div>

what do you mean by “failing”?  
what fails?

in any case,

it is (i just tried it, albeit in a separate environment 🙂 )

```bash
conda install -n base -c conda-forge COMPAS=0.15.5

```

not

```bash
conda install -n base COMPAS=0.15.5 -c conda-forge

```

---

<div class="post-metadata">

### Author: ![Pirouz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Pirouz](https://forum.compas-framework.org/u/Pirouz)
#### Post date: [April 6, 2020, 2:51pm UTC](https://forum.compas-framework.org/t/importing-obj-files/326/11 "2020-04-06T14:51:09Z")

</div>

Thanks for the additional tips about anaconda!  
BTW, did it have to be in uppercase letters? I finally managed to get conda to install this version by running this:  
conda create -n arch python=3.7 COMPAS=0.15.5 -c conda-forge

But, now, I am wondering how to navigate to this environment in vscode (I can only choose my python interpreter); becuase I still see the same version (0.11) in my vscode…

---

<div class="post-metadata">

### Author: ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)
#### Post date: [April 6, 2020, 2:56pm UTC](https://forum.compas-framework.org/t/importing-obj-files/326/12 "2020-04-06T14:56:55Z")

</div>

no, the uppercase is not necessary. weird though that is works with the arguments in the back. but if it works it works 🙂

you will have to restart vscode to make it aware of the environment.

as soon as you open a python file it will ask for an interpreter and then you should be able to select the python in the `arch` environment…

---

<div class="post-metadata">

### Author: ![Pirouz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Pirouz](https://forum.compas-framework.org/u/Pirouz)
#### Post date: [April 6, 2020, 3:17pm UTC](https://forum.compas-framework.org/t/importing-obj-files/326/13 "2020-04-06T15:17:01Z")

</div>

Managed to navigate to the new environment in vscode when choosing my python interpreter; but again I see that conda version is 0.11 (when I print ). I am getting a feeling that this problem is not related to compas so I apologize for taking your precious time with this; but do you think I am missing something in vscode; or would you recommend uninstalling and installing COMPAS again using these two:  
conda uninstall -arch compas  
conda install -arch python=3.7 -c conda-forge compas=0.15.5

ps. after uninstalling, I figured out it was still reading compas from the base environment, in spite of having chosen the python interpreter from the specific environment.

---

<div class="post-metadata">

### Author: ![tomvanmele](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.compas-framework.org/tomvanmele/32/13_2.png) [@tomvanmele](https://forum.compas-framework.org/u/tomvanmele)
#### Post date: [April 6, 2020, 3:44pm UTC](https://forum.compas-framework.org/t/importing-obj-files/326/14 "2020-04-06T15:44:40Z")

</div>

i would go through the trouble to set things up properly. it will save you time down the road…

that means removing all current environments, resetting your base environment, and making a dedicated environment for your current work.

it is a bit of extra work but things will work better and behave more predictable afterwards…
