# AWS Python Lambda giving Error: Invalid 'cross-device link' for patsy-0.5.1

**URL:** <https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165>\
**Category:** Serverless Framework\
**Tags:** aws, lambda\
**Created:** [January 2, 2020, 6:51am UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165 "2020-01-02T06:51:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SuprNerd](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@SuprNerd](https://forum.serverless.com/u/SuprNerd)\
**Post date:** [January 2, 2020, 6:51am UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165/1 "2020-01-02T06:51:21Z")

</div>

Hi everyone!

I’m trying to deploy Python lambda via Windows Powershell. I am trying to eventually get statsmodels into AWS Lambda however I am running into an ‘Invalid cross-device link’ and ‘Permission denied’ error with the patsy-0.5.1 Python module. If anyone knows an easier way to get statsmodels into AWS please let me know (maybe with layers - but then the size is too big?).  
Anyways! Here is my issue:

After calling: serverless deploy --force -v

This is the error I am getting:

Error --------------------------------------------------  
STDERR: ERROR: Exception:  
Traceback (most recent call last):  
File “/var/lang/lib/python3.7/shutil.py”, line 566, in move  
os.rename(src, real\_dst)  
**OSError: [Errno 18] Invalid cross-device link: ‘/tmp/pip-target-yxcd5g32/lib/python/patsy-0.5.1.dist-info’ -\> '/var/task/patsy-0.5.1.dist-info’**

During handling of the above exception, another exception occurred:

Traceback (most recent call last):  
File “/var/lang/lib/python3.7/site-packages/pip/\_internal/cli/base\_command.py”, line 153, in \_main  
status = self.run(options, args)  
File “/var/lang/lib/python3.7/site-packages/pip/\_internal/commands/install.py”, line 505, in run  
options.target\_dir, target\_temp\_dir, options.upgrade  
File “/var/lang/lib/python3.7/site-packages/pip/\_internal/commands/install.py”, line 563, in \_handle\_target\_dir  
target\_item\_dir  
File “/var/lang/lib/python3.7/shutil.py”, line 577, in move  
symlinks=True)  
File “/var/lang/lib/python3.7/shutil.py”, line 324, in copytree  
os.makedirs(dst)  
File “/var/lang/lib/python3.7/os.py”, line 221, in makedirs  
mkdir(name, mode)  
**PermissionError: [Errno 13] Permission denied: '/var/task/patsy-0.5.1.dist-info’**

```
  at C:\forecast\node_modules\serverless-python-requirements\lib\pip.js:320:13
  at Array.forEach (<anonymous>)
  at installRequirements (C:\forecast\node_modules\serverless-python-requirements\lib\pip.js:307:28)
  at installRequirementsIfNeeded (C:\forecast\node_modules\serverless-python-requirements\lib\pip.js:551:3)
  at ServerlessPythonRequirements.installAllRequirements (C:\forecast\node_modules\serverless-python-requirements\lib\pip.js:630:29)
  at ServerlessPythonRequirements.tryCatcher (C:\forecast\node_modules\bluebird\js\release\util.js:16:23)
  at Promise._settlePromiseFromHandler (C:\forecast\node_modules\bluebird\js\release\promise.js:547:31)
  at Promise._settlePromise (C:\forecast\node_modules\bluebird\js\release\promise.js:604:18)
  at Promise._settlePromise0 (C:\forecast\node_modules\bluebird\js\release\promise.js:649:10)
  at Promise._settlePromises (C:\forecast\node_modules\bluebird\js\release\promise.js:729:18)
  at _drainQueueStep (C:\forecast\node_modules\bluebird\js\release\async.js:93:12)
  at _drainQueue (C:\forecast\node_modules\bluebird\js\release\async.js:86:9)
  at Async._drainQueues (C:\forecast\node_modules\bluebird\js\release\async.js:102:5)
  at Immediate.Async.drainQueues [as _onImmediate] (C:\forecast\node_modules\bluebird\js\release\async.js:15:14)
  at processImmediate (internal/timers.js:439:21)
  at process.topLevelDomainCallback (domain.js:130:23)

```

Thanks for any help!!

---

<div class="post-metadata">

**Author:** ![garethmcc](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/garethmcc/32/2276_2.png) [@garethmcc](https://forum.serverless.com/u/garethmcc)\
**Post date:** [January 3, 2020, 10:14am UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165/2 "2020-01-03T10:14:55Z")

</div>

Hi SuprNerd, and welcome to the community. It looks as if the library you are trying to use is attempting to create some kind of symlink on the Lambda. The structure of a Lambda though does not necessarily allow this. A quick Google of ` Invalid cross-device link` seems to indicate that symlinking across partitions or devices is not possible, which must mean that /tmp and /var are not on the same device.

This is just a guess however as I am no Python expert.

---

<div class="post-metadata">

**Author:** ![ChaithraKumar123](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@ChaithraKumar123](https://forum.serverless.com/u/ChaithraKumar123)\
**Post date:** [January 5, 2020, 9:30am UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165/3 "2020-01-05T09:30:53Z")

</div>

i am running into a similar error.Any solutions or help?  
but it’s with any python package i try to use i get invalid cross link error

---

<div class="post-metadata">

**Author:** ![SuprNerd](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@SuprNerd](https://forum.serverless.com/u/SuprNerd)\
**Post date:** [January 7, 2020, 11:19pm UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165/4 "2020-01-07T23:19:32Z")

</div>

Any update on this as of yet? Still struggling with the issue haha

---

<div class="post-metadata">

**Author:** ![ChaithraKumar123](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@ChaithraKumar123](https://forum.serverless.com/u/ChaithraKumar123)\
**Post date:** [January 7, 2020, 11:40pm UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165/5 "2020-01-07T23:40:02Z")

</div>

just make sure all your files exists in the same directory.  
Especially we you run sls deploy make sure you run that with proper permission.  
just do ls -la you will get list of all hidden files. .serveless directory must be create in the same filesystem.  
if its created in the root and you have other files in your user filesystem.Just try avoiding sudo.  
if sls deploy (without sudo) throws error remove .serveless directory and again run the sls deploy without sudo.  
The key is all your files must be in same filesystem.  
This solved my error!  
Hope this helps!

---

<div class="post-metadata">

**Author:** ![SuprNerd](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@SuprNerd](https://forum.serverless.com/u/SuprNerd)\
**Post date:** [January 8, 2020, 12:30am UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165/6 "2020-01-08T00:30:17Z")

</div>

Can I ask what are the contents of your .serverless directory? I just have requirements.txt in there…

---

<div class="post-metadata">

**Author:** ![ChaithraKumar123](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@ChaithraKumar123](https://forum.serverless.com/u/ChaithraKumar123)\
**Post date:** [January 8, 2020, 1:53am UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165/7 "2020-01-08T01:53:38Z")

</div>

It is created during runtime.  
when you do sls deploy

---

<div class="post-metadata">

**Author:** ![ggrantrowberry](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/ggrantrowberry/32/4809_2.png) [@ggrantrowberry](https://forum.serverless.com/u/ggrantrowberry)\
**Post date:** [December 2, 2020, 2:44am UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165/8 "2020-12-02T02:44:38Z")

</div>

I had a similar issue. I looked looked up the error OSError: [Errno 18] Invalid cross-device link. Some people said it was an issue with pip so I tried pip install --upgrade pip.  
Here’s what did work for me. (Also I am assuming you are using the serverless-python-requirements plugin.)

```auto
rm -rf /venv //Deleted my virtual environment
python3 -m venv venv //Re created my venv
source venv/bin/activate //Activated my venv
pip install --upgrade pip //Upgraded pip. I'm not sure if that was necessary but I did it.
pip install -r requirements.txt //Installed everything again

```

After doing all that I deployed again and it worked.  
It seems like the issue was something in my virtual environment

---

<div class="post-metadata">

**Author:** ![sebamacchia](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/sebamacchia/32/6049_2.png) [@sebamacchia](https://forum.serverless.com/u/sebamacchia)\
**Post date:** [July 29, 2021, 6:32pm UTC](https://forum.serverless.com/t/aws-python-lambda-giving-error-invalid-cross-device-link-for-patsy-0-5-1/10165/9 "2021-07-29T18:32:35Z")

</div>

Any help here?, still with that error (try all you suggested here)
