# Trouble loading python file using PythonKit

**URL:** <https://forums.swift.org/t/trouble-loading-python-file-using-pythonkit/48008>\
**Category:** Using Swift\
**Tags:** python, pythonkit\
**Created:** [May 10, 2021, 1:16am UTC](https://forums.swift.org/t/trouble-loading-python-file-using-pythonkit/48008 "2021-05-10T01:16:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CPcommunity](https://avatars.discourse-cdn.com/v4/letter/c/ad7895/32.png) [@CPcommunity](https://forums.swift.org/u/CPcommunity)\
**Post date:** [May 10, 2021, 1:16am UTC](https://forums.swift.org/t/trouble-loading-python-file-using-pythonkit/48008/1 "2021-05-10T01:16:14Z")

</div>

I have followed the various tutorials so that I can run a python file from within Swift. I have gotten everything set up and run the file, but I get the following error.

> Could not access PythonObject member

I have took the following steps so that I can access the python file.

- In Targets -\> Signing & Capabilities, set hardened runtime to Disable Library Validation
- In Targets -\> Signing & Capabilities, remove App Sandbox

From my research, those two things should be all I need to do besides adding the PythonKit package and preparing the Python file.

My code is below:

```swift
import Cocoa
import PythonKit
import Alamofire

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let sys = Python.import("sys")

        print("Python \(sys.version_info.major).\(sys.version_info.minor)")
        print("Python Version: \(sys.version)")
        sys.path.append("/Users/username/")
        let example = Python.import("test")
        example.main()
    }

 }

```

The error occurs on the last line. The file path in sys.path.append is correct.

Mac OS: 11.2.2 Xcode version: 12.5

---

<div class="post-metadata">

**Author:** ![NG-Corp](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ng-corp/32/28556_2.png) [@NG-Corp](https://forums.swift.org/u/NG-Corp)\
**Post date:** [January 28, 2023, 10:34pm UTC](https://forums.swift.org/t/trouble-loading-python-file-using-pythonkit/48008/2 "2023-01-28T22:34:51Z")

</div>

Try transferring python code into a different code file. It worked for me when I tried it.
